The post shows a way to move 3D model to the original point in world coordinate system.

The file CMakeLists.txt is similar to https://www.weiy.city/2021/12/find-closest-plane-between-points-in-3d-by-covariance-matrix/.

The included file point.hpp can be found in https://www.weiy.city/2020/09/project-point-on-line-and-plane-by-special-direction/.

#include <iostream>
#include <vtkPolyData.h>
#include <vtkActor.h>
#include <vtkTransformFilter.h>

#include "./point.hpp"
#include <vtkTransform.h>
#include <vtkSTLReader.h>
#include <vtkSTLWriter.h>

#define vtkSPtr vtkSmartPointer
#define vtkSPtrNew(Var, Type) vtkSPtr<Type> Var = vtkSPtr<Type>::New();

int main() {
    std::string path = "move.stl";
    vtkSPtrNew( reader, vtkSTLReader );
    reader->SetFileName( path.c_str() );
    reader->Update();

    vtkPolyData *data = reader->GetOutput();
    data->ComputeBounds();
    Point dataCenter( data->GetCenter() );
    vtkSPtrNew( trans, vtkTransform );
    trans->Translate( (-dataCenter).point );
    trans->Update();
    vtkSPtrNew( transFilter, vtkTransformFilter );
    transFilter->SetInputData( data );
    transFilter->SetTransform( trans );
    transFilter->Update();

    vtkSPtrNew( writer, vtkSTLWriter );
    writer->SetInputData( transFilter->GetOutput() );
    writer->SetFileName( "newData.stl" );
    writer->Write();
    return 0;
}

Categories: VTK

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

XML To JSON
: Input your strings, the tool can convert XML to JSON for you.

X
0
Would love your thoughts, please comment.x
()
x