[vtkusers] can't write obj files

Gabriele zibalmail at gmail.com
Fri May 29 12:51:21 EDT 2009


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 );
 
    
}



More information about the vtkusers mailing list