[vtkusers] Weird vtkClipPolyData error when using an *.obj
Jérôme
jerome.velut at gmail.com
Thu May 19 15:32:29 EDT 2011
Hi,
If you want to track the bug, you should avoid a so complicated code (I got
some
build error, I don't know if my fixes are coherent with your issue...). The
error
message deals with Clip, so basically you write a test pipeline like this :
reader -> clip -> update
If the error doesn't occur, add and test new functionnality step by step.
For your case, I just opened your data with paraview : it seems that your
obj file
doesn't contain point data. Please, try to generate scalar data before
clipping,
as the error says.
Jerome
2011/5/19 agerlach <agerlach at gmail.com>
> OK. Here is an attempt at an example of my problem. Unfortunately for some
> reason I cannot get an observer to work to identify the end of the
> tracerWidet event. I'm sure it is something simple. So, may need some help
> getting that to work before I will be able to demonstrate my problem.
> (Please be patient, I'm a newbie) In my main application it uses a gui so I
> use the gui button press to turn tracerWidet off and then compute the area.
>
> To run place the following ply and obj model and texture in the same folder
> as the exe.
> http://www.intellimedsystems.com/files/AreaTruth_T1.jpg Texture
> http://www.intellimedsystems.com/files/AreaTruth.ply ply model
> http://www.intellimedsystems.com/files/AreaTruth.obj obj model
>
> Run and type y to use the obj otherwise the ply will be loaded.
>
> #include <vtkPolyDataMapper.h>
> #include <vtkActor.h>
> #include <vtkRenderWindow.h>
> #include <vtkRenderer.h>
> #include <vtkRenderWindowInteractor.h>
> #include <vtkPolyData.h>
> #include <vtkSmartPointer.h>
> #include <vtkSphereSource.h>
> #include <vtkImageTracerWidget.h>
> #include <vtkInteractorStyleTrackballCamera.h>
> #include <vtkSelectPolyData.h>
> #include <vtkClipPolyData.h>
> #include <vtkMassProperties.h>
> #include <vtkPLYReader.h>
> #include <vtkOBJReader.h>
> #include <vtkJPEGReader.h>
> #include <vtkTexture.h>
> #include <vtkCallbackCommand.h>
>
>
> class vtkITWCallback : public vtkCommand
>
> {
>
> public:
> static vtkITWCallback *New()
> { return new vtkITWCallback; }
>
> virtual void Execute(vtkObject *caller, unsigned long, void*)
> {
> vtkImageTracerWidget *tracer =
> reinterpret_cast<vtkImageTracerWidget*>(caller);
>
> if(tracer->IsClosed()) {
> vtkSmartPointer<vtkPolyData> tracePolyData =
> vtkSmartPointer<vtkPolyData>::New();
>
> tracer->GetPath(tracePolyData);
> std::cout << "There are " << tracePolyData->GetNumberOfPoints()
> << " points in the path." << std::endl;
>
> vtkSmartPointer<vtkSelectPolyData> loop =
> vtkSmartPointer<vtkSelectPolyData>::New();
> loop->SetInput(polyData);
> loop->SetLoop(tracePolyData->GetPoints());
> loop->SetSelectionModeToSmallestRegion();
> loop->Update();
>
> vtkSmartPointer<vtkClipPolyData> clip =
> vtkSmartPointer<vtkClipPolyData>::New();
> clip->SetInput(loop->GetOutput());
> clip->Update();
>
> vtkSmartPointer<vtkMassProperties> mass =
> vtkSmartPointer<vtkMassProperties>::New();
> mass->SetInput(clip->GetOutput());
> std::cout << "Area = " << mass->GetSurfaceArea() << "[mm]";
> }
> else
> std::cout << "Trace not closed";
> }
>
> vtkITWCallback():polyData(0){}
>
> vtkPolyData *polyData;
>
>
> };
>
> int main(int argc, char *argv[])
> {
> bool usePLY = true;
> bool hasTexture = false;
>
> std::string input = " ";
> std::cout << "Use obj (y/n):\n>";
> std::getline(cin,input);
>
> if(input == "y" || input == "Y")
> usePLY = false;
>
> vtkSmartPointer<vtkPolyData> polyData;
> polyData = vtkSmartPointer<vtkPolyData>::New();
>
> vtkSmartPointer<vtkTexture> texture =
> vtkSmartPointer<vtkTexture>::New();
>
> if(usePLY)
> {
> std::cout << "Using *.ply";
> vtkSmartPointer<vtkPLYReader> plyReader =
> vtkSmartPointer<vtkPLYReader>::New();
>
> plyReader->SetFileName("AreaTruth.ply");
> plyReader->Update();
> polyData = plyReader->GetOutput();
>
> }
> else
> {
> std::cout << "Using *.obj";
> vtkSmartPointer<vtkOBJReader> objReader =
> vtkSmartPointer<vtkOBJReader>::New();
>
> objReader->SetFileName("AreaTruth.obj");
> objReader->Update();
> polyData = objReader->GetOutput();
>
> hasTexture = true;
>
> vtkSmartPointer<vtkJPEGReader> jpgReader =
> vtkSmartPointer<vtkJPEGReader>::New();
> jpgReader->SetFileName("AreaTruth_T1.jpg");
> jpgReader->Update();
>
>
> texture->SetInputConnection(jpgReader->GetOutputPort());
> texture->InterpolateOn();
>
>
> }
>
> // Create a mapper and actor
> vtkSmartPointer<vtkPolyDataMapper> mapper =
> vtkSmartPointer<vtkPolyDataMapper>::New();
> mapper->SetInput(polyData);
> vtkSmartPointer<vtkActor> actor =
> vtkSmartPointer<vtkActor>::New();
> actor->SetMapper(mapper);
>
> if(hasTexture)
> actor->SetTexture(texture);
>
> // A renderer and render window
> vtkSmartPointer<vtkRenderer> renderer =
> vtkSmartPointer<vtkRenderer>::New();
> vtkSmartPointer<vtkRenderWindow> renderWindow =
> vtkSmartPointer<vtkRenderWindow>::New();
> renderWindow->AddRenderer(renderer);
> renderer->AddActor(actor);
>
> // An interactor
> vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
> vtkSmartPointer<vtkRenderWindowInteractor>::New();
> renderWindowInteractor->SetRenderWindow(renderWindow);
>
> vtkSmartPointer<vtkInteractorStyleTrackballCamera> style =
> vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
>
> renderWindowInteractor->SetInteractorStyle(style);
>
> vtkSmartPointer<vtkCallbackCommand> callback =
> vtkSmartPointer<vtkCallbackCommand>::New();
> callback->SetCallback(CallbackFunction);
>
> vtkSmartPointer<vtkITWCallback> itwCallback =
> vtkSmartPointer<vtkITWCallback>::New();
> itwCallback->polyData = polyData;
>
>
>
> vtkSmartPointer<vtkImageTracerWidget> tracerWidget;
> tracerWidget = vtkSmartPointer<vtkImageTracerWidget>::New();
> tracerWidget->SetInteractor(renderWindowInteractor);
> tracerWidget->SetViewProp(actor);
> tracerWidget->AutoCloseOn();
> tracerWidget->AddObserver(vtkCommand::EndInteractionEvent, itwCallback);
> tracerWidget->On();
> renderWindow->Render();
>
> renderWindowInteractor->Initialize();
> renderWindow->Render();
>
>
>
>
> // Begin mouse interaction
>
> renderWindowInteractor->Start();
>
> return EXIT_SUCCESS;
> }
>
>
> --
> View this message in context:
> http://vtk.1045678.n5.nabble.com/Weird-vtkClipPolyData-error-when-using-an-obj-tp4408314p4410434.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110519/b4e41d61/attachment.htm>
More information about the vtkusers
mailing list