vtkOBJReader example for C++

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

vtkOBJReader example for C++

Sergey Programmer
Hi all!

Can anybody provide an example (C++ would be perfect) how to read OBJ files using vtkOBJReader? I'm trying the following with no success:

My class extends vtkOBJReader, in the Open method I do

    SetFileName( fname.c_str() );
    Update();
    vtkDataObject * src = GetOutput();

and then src is 0 even after I specified correct filename. What am I doing wrong?

Regards,
C


_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: vtkOBJReader example for C++

Bill Lorensen
http://www.vtk.org/Wiki/VTK/Examples/IO/ReadOBJ

On Tue, Jul 13, 2010 at 8:44 AM, Sergey Programmer <[hidden email]> wrote:

> Hi all!
>
> Can anybody provide an example (C++ would be perfect) how to read OBJ files
> using vtkOBJReader? I'm trying the following with no success:
>
> My class extends vtkOBJReader, in the Open method I do
>
>     SetFileName( fname.c_str() );
>     Update();
>     vtkDataObject * src = GetOutput();
>
> and then src is 0 even after I specified correct filename. What am I doing
> wrong?
>
> Regards,
> C
>
>
> _______________________________________________
> 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
>
>
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: vtkOBJReader example for C++

Sergey Programmer
Thank you, Bill!

My mistake was that I looked into GetOutput() from debugger, zeros in most fields confused me. However, the structure was okay and after I added actor and updated renderer, data appeared.

Regards,
C


On Tue, Jul 13, 2010 at 5:00 PM, Bill Lorensen <[hidden email]> wrote:
http://www.vtk.org/Wiki/VTK/Examples/IO/ReadOBJ

On Tue, Jul 13, 2010 at 8:44 AM, Sergey Programmer <[hidden email]> wrote:
> Hi all!
>
> Can anybody provide an example (C++ would be perfect) how to read OBJ files
> using vtkOBJReader? I'm trying the following with no success:
>
> My class extends vtkOBJReader, in the Open method I do
>
>     SetFileName( fname.c_str() );
>     Update();
>     vtkDataObject * src = GetOutput();
>
> and then src is 0 even after I specified correct filename. What am I doing
> wrong?
>
> Regards,
> C
>
>
> _______________________________________________
> 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
>
>


_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: vtkOBJReader example for C++

shayan moradkhani
hi,
what is the problem with this code snippet:
Capture.JPG <http://vtk.1045678.n5.nabble.com/file/t342474/Capture.JPG>  

i followed the obj-reader link and only changed the file name. but still
getting nothing



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: vtkOBJReader example for C++

Sgouros, Thomas
Hi:

I'm afraid I don't have any useful advice about your issue, but there are two OBJ readers in VTK, and I have found more satisfaction using objImporter, which has much more of the functionality I'd expect to find in an OBJ handling class.

 -Tom

On Wed, Jun 27, 2018 at 5:14 AM, shayan moradkhani <[hidden email]> wrote:
hi,
what is the problem with this code snippet:
Capture.JPG <http://vtk.1045678.n5.nabble.com/file/t342474/Capture.JPG

i followed the obj-reader link and only changed the file name. but still
getting nothing



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers


_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: vtkOBJReader example for C++

shayan moradkhani
hi,
i have been loading obj files in vtk successfully. however, i want to get
the center coordinates of the loaded model to move the whole object by
moving its center.
is there any way to do that?
thanks
Shayan



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: vtkOBJReader example for C++

shayan moradkhani
int main(int, char *[])
{
        std::string filename = "Part3.obj";
        vtkSmartPointer<vtkOBJReader> reader =
vtkSmartPointer<vtkOBJReader>::New();
        reader->SetFileName(filename.c_str());
        reader->Update();
        // Visualize
        vtkSmartPointer<vtkPolyDataMapper> mapper =
                vtkSmartPointer<vtkPolyDataMapper>::New();
        mapper->SetInputConnection(reader->GetOutputPort());
       
        vtkSmartPointer<vtkActor> actor =
                vtkSmartPointer<vtkActor>::New();
        actor->SetMapper(mapper);
        actor->GetProperty()->SetColor(1.0000, 0.3882, 0.2784);
       

        vtkSmartPointer<vtkRenderer> renderer =
                vtkSmartPointer<vtkRenderer>::New();
        renderer->AddActor(actor);
        renderer->SetBackground(.1, .3, .3); // Background color green
        // Zoom in a little by accessing the camera and invoking its "Zoom" method.
        renderer->ResetCamera();
        //renderer->GetActiveCamera()->Zoom(1.5);

        vtkSmartPointer<vtkRenderWindow> renderWindow =
                vtkSmartPointer<vtkRenderWindow>::New();
        renderWindow->SetSize(800, 600);
        renderWindow->AddRenderer(renderer);

        vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
                vtkSmartPointer<vtkRenderWindowInteractor>::New();
        renderWindowInteractor->SetRenderWindow(renderWindow);



        renderWindowInteractor->Start();

        return EXIT_SUCCESS;
}

this is what i have. however, when i load in vtk, i have no idead where the
model is loaded (with respect to the global coordinate system). if i could
get its center, it would be easier i guess to apply transformation on the
object



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: vtkOBJReader example for C++

terminator via vtkusers
You probably need to do something like
 reader->GetOutput()->GetBounds() or reader->GetOutput()->GetCenter()


Todd Martin, PhD.
Freelance Engineer/Software Architect.



On Monday, July 2, 2018, 11:30:42 PM GMT+12, shayan moradkhani <[hidden email]> wrote:


int main(int, char *[])
{
    std::string filename = "Part3.obj";
    vtkSmartPointer<vtkOBJReader> reader =
vtkSmartPointer<vtkOBJReader>::New();
    reader->SetFileName(filename.c_str());
    reader->Update();
    // Visualize
    vtkSmartPointer<vtkPolyDataMapper> mapper =
        vtkSmartPointer<vtkPolyDataMapper>::New();
    mapper->SetInputConnection(reader->GetOutputPort());
   
    vtkSmartPointer<vtkActor> actor =
        vtkSmartPointer<vtkActor>::New();
    actor->SetMapper(mapper);
    actor->GetProperty()->SetColor(1.0000, 0.3882, 0.2784);
   

    vtkSmartPointer<vtkRenderer> renderer =
        vtkSmartPointer<vtkRenderer>::New();
    renderer->AddActor(actor);
    renderer->SetBackground(.1, .3, .3); // Background color green   
    // Zoom in a little by accessing the camera and invoking its "Zoom" method.
    renderer->ResetCamera();
    //renderer->GetActiveCamera()->Zoom(1.5);

    vtkSmartPointer<vtkRenderWindow> renderWindow =
        vtkSmartPointer<vtkRenderWindow>::New();
    renderWindow->SetSize(800, 600);
    renderWindow->AddRenderer(renderer);

    vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
        vtkSmartPointer<vtkRenderWindowInteractor>::New();
    renderWindowInteractor->SetRenderWindow(renderWindow);



    renderWindowInteractor->Start();

    return EXIT_SUCCESS;
}

this is what i have. however, when i load in vtk, i have no idead where the
model is loaded (with respect to the global coordinate system). if i could
get its center, it would be easier i guess to apply transformation on the

object



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers

_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers