[vtkusers] can't write obj files
David Doria
daviddoria at gmail.com
Fri May 29 13:33:10 EDT 2009
Gabriele,
I am still not sure why this is not included - you can use my WriteAPolyData
function that I cut out/modified from the vtkOBJExporter.
Replace vtkOBJExporter.cxx/h in VTK/Rendering - then see WriteOBJ.cpp for an
example.
http://www.rpi.edu/~doriad/OBJWriter/
Maybe someone with write access can commit this?
Thanks,
David
On Fri, May 29, 2009 at 12:51 PM, Gabriele <zibalmail at gmail.com> wrote:
> Hello,
>
> I have spent a few hours already on this thing and I can't really
> understand why it does not work.
>
> I am trying to save an .obj file using vtkObjExporter, but only the mtl
> file is saved, no .obj.
>
> I include a simple function that should, in my humble opinion, read an obj
> file and just save it with a different name, but again only stores the .mtl
> file. Can anyone guess what's wrong?
>
> Thanks a lot,
> G
>
>
> #include <vtkOBJReader.h>
> #include <string>
> #include <vtkRenderer.h>
> #include <vtkRenderWindow.h>
> #include <vtkRenderWindowInteractor.h>
> #include <vtkOBJExporter.h>
>
>
> void tryIO(std::string& name){
>
> vtkOBJReader *myObjReader;
> myObjReader = vtkOBJReader::New();
> myObjReader->SetFileName(name.c_str()); myObjReader->Update();
> vtkPolyData* model = vtkPolyData::New();
> model->DeepCopy(myObjReader->GetOutput());
> myObjReader->Delete();
> vtkOBJExporter* objExporter = vtkOBJExporter::New();
> std::string outName(name.substr(0, name.find_last_of('.')));
> outName += "_processed";
> objExporter->SetFilePrefix(outName.c_str());
> //set renderer to the read model
> vtkRenderer *renderer;
> renderer = vtkRenderer::New();
> vtkPolyDataMapper *myDataMapper = vtkPolyDataMapper::New();
> myDataMapper->SetInput(model);
> vtkActor *myActor = vtkActor::New();
> myActor->SetMapper(myDataMapper);
> //assign our actor to the renderer
> renderer->AddActor(myActor);
> vtkRenderWindow *renWin = vtkRenderWindow::New();
> renWin->AddRenderer(renderer);
> objExporter->SetRenderWindow(renWin);
> objExporter->Write();
> objExporter->Delete(); renWin->Delete();
> renderer->Delete();
> myDataMapper->Delete();
> myActor->Delete();
> }
>
>
>
>
> int main(int argc, char* argv[]){
> std::string objName(argv[1]);
> tryIO( objName );
>
> }
> _______________________________________________
> 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/20090529/ac2b2ee1/attachment.htm>
More information about the vtkusers
mailing list