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

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
trackback

[…] How to make the image’s center as actor’s position? Just like rewrite 3D model to make center as (0,0,0), related post: https://www.weiy.city/2022/01/rewrite-file-to-move-3d-model-to-origin-point/ […]

Tex To PDF
: convert the Latex file which suffix is tex to a PDF file

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