<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Dear all,<div class=""><br class=""></div><div class="">I am quiet new to vtk. I meet some problems using vtk. This is what I am trying to do:</div><div class=""><br class=""></div><div class="">1. read an stl</div><div class="">2. cut the stl in half by a plane</div><div class="">3. add the surfaces to each parts to make it solid, ready for 3d printing (intersection of the plane and the stl model)</div><div class="">4. save the two separate stl file.</div><div class=""><br class=""></div><div class="">I don’t know how to add the surface now..</div><div class=""><br class=""></div><div class="">I know add backface on actor will now help…</div><div class=""><br class=""></div><div class="">I referred this:</div><div class=""><a href="http://www.paraview.org/Wiki/VTK/Examples/Cxx/Meshes/SolidClip" class="">http://www.paraview.org/Wiki/VTK/Examples/Cxx/Meshes/SolidClip</a></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">This is my current code:</div><div class=""><br class=""></div><div class=""><div class="">#include "vtkActor.h"</div><div class="">#include "vtkClipPolyData.h"</div><div class="">#include "vtkPlane.h"</div><div class="">#include "vtkInteractorObserver.h"</div><div class="">#include "vtkInteractorStyleSwitch.h"</div><div class="">#include "vtkPolyDataMapper.h"</div><div class="">#include "vtkRenderer.h"</div><div class="">#include "vtkRenderWindow.h"</div><div class="">#include "vtkRenderWindowInteractor.h"</div><div class="">#include "vtkSmartPointer.h"</div><div class="">#include "vtkSphereSource.h"</div><div class="">#include <vtkPolyData.h></div><div class="">#include <vtkSTLReader.h></div><div class="">#include <vtkSmartPointer.h></div><div class="">#include <vtkPolyDataMapper.h></div><div class="">#include <vtkActor.h></div><div class="">#include <vtkRenderWindow.h></div><div class="">#include <vtkRenderer.h></div><div class="">#include <vtkRenderWindowInteractor.h></div><div class="">#include <vtkClipPolyData.h></div><div class="">#include <vtkPlane.h></div><div class="">#include <vtkProperty.h></div><div class="">#include <vtkSTLWriter.h></div><div class=""><br class=""></div><div class="">using namespace std;</div><div class="">int main(int argc, char ** argv) {</div><div class=""><br class=""></div><div class=""> if ( argc != 2 )</div><div class=""> {</div><div class=""> cout << "Required parameters: Filename" << endl;</div><div class=""> return EXIT_FAILURE;</div><div class=""> }</div><div class=""> </div><div class=""> std::string inputFilename = argv[1];</div><div class=""> </div><div class=""> vtkSmartPointer<vtkSTLReader> reader =</div><div class=""> vtkSmartPointer<vtkSTLReader>::New();</div><div class=""> reader->SetFileName(inputFilename.c_str());</div><div class=""> reader->Update();</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""> vtkSmartPointer<vtkClipPolyData> clip =</div><div class=""> vtkSmartPointer<vtkClipPolyData>::New();</div><div class=""> clip->SetValue(0);</div><div class=""> clip->GenerateClippedOutputOn();</div><div class=""> clip->SetInputConnection(reader->GetOutputPort());</div><div class=""><br class=""></div><div class=""> vtkSmartPointer<vtkPlane> plane =</div><div class=""> vtkSmartPointer<vtkPlane>::New();</div><div class=""> //plane->SetNormal(-1.0, 0.0, 0.0);</div><div class=""> plane->SetNormal(0.0, 0.0, -1);</div><div class=""> plane->SetOrigin(0, 0, 12);</div><div class=""> clip->SetClipFunction (plane);</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""> vtkSmartPointer<vtkPolyDataMapper> polyDataMapper =</div><div class=""> vtkSmartPointer<vtkPolyDataMapper>::New();</div><div class=""> polyDataMapper->SetInputConnection(clip->GetOutputPort());</div><div class=""> vtkSmartPointer<vtkActor> actor =</div><div class=""> vtkSmartPointer<vtkActor>::New();</div><div class=""> actor->SetMapper(polyDataMapper);</div><div class=""><br class=""></div><div class=""> // Create a property to be used for the back faces. Turn off all</div><div class=""> // shading by specifying 0 weights for specular and diffuse. Max the</div><div class=""> // ambient.</div><div class=""> vtkSmartPointer<vtkProperty> backFaces =</div><div class=""> vtkSmartPointer<vtkProperty>::New();</div><div class=""> backFaces->SetSpecular(0.0);</div><div class=""> backFaces->SetDiffuse(0.0);</div><div class=""> backFaces->SetAmbient(1.0);</div><div class=""> backFaces->SetAmbientColor(1.0000, 0.3882, 0.2784);</div><div class=""> </div><div class=""> actor->SetBackfaceProperty(backFaces);</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""> vtkSmartPointer<vtkRenderWindow> renderWindow =</div><div class=""> vtkSmartPointer<vtkRenderWindow>::New();</div><div class=""> renderWindow->SetSize(800,600);</div><div class=""> renderWindow->SetWindowName("VTK");</div><div class=""> vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =</div><div class=""> vtkSmartPointer<vtkRenderWindowInteractor>::New();</div><div class=""> renderWindowInteractor->SetRenderWindow(renderWindow);</div><div class=""> vtkSmartPointer<vtkRenderer> renderer =</div><div class=""> vtkSmartPointer<vtkRenderer>::New();</div><div class=""> renderer->AddActor(actor);</div><div class=""> renderWindow->AddRenderer(renderer);</div><div class=""> vtkInteractorStyleSwitch * styleSwitch</div><div class=""> = vtkInteractorStyleSwitch::SafeDownCast(</div><div class=""> renderWindowInteractor->GetInteractorStyle());</div><div class=""> if (styleSwitch)</div><div class=""> styleSwitch->SetCurrentStyleToTrackballCamera();</div><div class=""> renderWindow->Render();</div><div class=""> renderWindowInteractor->Start();</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""> // save stl</div><div class=""><br class=""></div><div class=""> vtkSmartPointer<vtkSTLWriter> stlWriter =</div><div class=""> vtkSmartPointer<vtkSTLWriter>::New();</div><div class=""> stlWriter->SetFileName("cut.stl");</div><div class=""> stlWriter->SetInputConnection(clip->GetOutputPort());</div><div class=""> stlWriter->Write();</div><div class="">}</div><div class=""><br class=""></div><div class=""><br class=""></div></div><div class="">Any suggestion would be helpful, thanks in advance!</div><div class=""><br class=""></div><div class="">Best wishes,</div><div class="">Shiyu Wang</div><br class=""><br class="">
<br class=""></body></html>