[vtkusers] Insert raw openGL calls in vtk

David Cole DLRdave at aol.com
Fri Apr 10 08:27:31 EDT 2015


The clipping planes are automatically set when you call
ResetCameraClippingRange based on the sum total of the bounds of the
visible actors in the scene.

If you need different clipping planes, you'll have to add an actor with the
appropriate bounds, or figure out how to intercept and override VTK's
setting of the clipping planes.

If you are calling code within VTK, there are many built-in callers to
ResetCameraClippingRange, so I would recommend having all of your actors
participate in the bounds computation by reporting their correct bounds in
VTK world coordinates.


HTH,
David C.



On Friday, April 10, 2015, Sergio Vera <sergio.vera at alma3d.com> wrote:

> Dear Sankhesh and Aashish
>
> many thanks for your heping advices.
>
> I've finally made it work (more or less)
> I did it by giving the opengl mapper a faked input as you suggested.
> My opengl stuff is being actually drawn to the screen although it seems to
> be heavily clipped and/or dissapearing depending on the polydata that I
> provide as a "fake" input to my rawGLMapper.I guess is some part of the vtk
> pipeline confused about having an actor with bogus bounds (the bounds of a
> completely different polydata). Or perhaps something related to the depth /
> color buffers or frustum clipping planes perhaps (i have to dig a little
> more at it)
>
>
> Many thanks
>
> On Thu, Apr 2, 2015 at 6:48 PM, Sankhesh Jhaveri <
> sankhesh.jhaveri at kitware.com> wrote:
>
>> Hello Sergio,
>>
>> A couple of things:
>>
>> 1. If you look at the vtkPolyDataMapper::Render() method, it calls
>> RenderPiece only if there is input information set on the mapper. I guess
>> your code does not provide an input to the mapper, and hence, RenderPiece
>> (and Draw) is not called.
>>
>> 2. The vtkRenderer::Render() method clears the color and depth buffers by
>> default. You'll have to work around that to make sure the GL objects are
>> preserved.
>>
>> Hope that helps.
>>
>>
>>
>> Best Regards,
>>
>> Sankhesh Jhaveri
>> Research & Development Engineer
>> Kitware, Inc.
>> *Phone*: (518) 881 4417
>> *Fax*: (518) 371 4573
>>
>>
>>
>> On Wed, Apr 1, 2015 at 11:01 AM, Sergio Vera <sergio.vera at alma3d.com>
>> wrote:
>>
>>> Dear Aashish,
>>>
>>> thanks for your time. At the moment it is kinda difficult to switch to
>>> OpenGL2 backend, manily because the VTK (5.10) we use is pulled by the CTK
>>> superbuild. I could try to switch to the experimental branch of CTK with
>>> support for vtk 6 and try to modifly the superbuild so VTK uses the OpenGL2
>>> backend.
>>>
>>> Currently I'm testing stuff using this toy example (based on a VTK
>>> example)
>>>
>>> #include <iostream>
>>> #include <vtkProp3D.h>
>>> #include <vtkVersion.h>
>>> #include <vtkSmartPointer.h>
>>> #include <vtkCellArray.h>
>>> #include <vtkCellData.h>
>>> #include <vtkDoubleArray.h>
>>> #include <vtkPoints.h>
>>> #include <vtkLine.h>
>>> #include <vtkPolyData.h>
>>> #include <vtkPolyDataMapper.h>
>>> #include <vtkActor.h>
>>> #include <vtkRenderWindow.h>
>>> #include <vtkRenderer.h>
>>> #include <vtkRenderWindowInteractor.h>
>>> #include <vtkOpenGL.h> // For export macro
>>> #include <vtkObjectFactory.h>
>>> #include <vtkMapper.h>
>>> #include <vtkOpenGLPolyDataMapper.h>
>>> #include <vtkgl.h>
>>> #include <vtkViewport.h>
>>>
>>> #include <GL/gl.h>
>>>
>>> class  myMapper : public vtkOpenGLPolyDataMapper
>>> {
>>> public:
>>>     static myMapper *New();
>>>     vtkTypeMacro(myMapper, vtkOpenGLPolyDataMapper);
>>>
>>>     virtual void RenderPiece(vtkRenderer *aren, vtkActor *act);
>>>     virtual int Draw(vtkRenderer *aren, vtkActor *act);
>>>
>>> protected:
>>>
>>> private:
>>>
>>> };
>>>
>>> vtkStandardNewMacro(myMapper);
>>>
>>> void
>>> myMapper::RenderPiece(vtkRenderer* a_ren, vtkActor* a_act)
>>> {
>>>   std::cout << "RenderPiece" << std::endl;
>>>   glDisable( GL_LIGHTING);
>>>     glBegin(GL_LINES);
>>>     glVertex3f(0, 1, 0);
>>>     glVertex3f(1, 1., 0.);
>>>     glEnd();
>>> }
>>>
>>> int
>>> myMapper::Draw(vtkRenderer* a_ren, vtkActor* a_act)
>>> {
>>>     std::cout << "Draw" << std::endl;
>>>
>>>     glDisable( GL_LIGHTING);
>>>     glBegin(GL_LINES);
>>>     glVertex3f(0, 1, 0);
>>>     glVertex3f(1, 1., 0.);
>>>     glEnd();}
>>>
>>>
>>> int main(int, char *[])
>>> {
>>>   std::cout << "Main" << std::endl;
>>>   // Create three points. Join (Origin and P0) with a red line and
>>>   // (Origin and P1) with a green line
>>>   double origin[3] = {0.0, 0.0, 0.0};
>>>   double p0[3] = {1.0, 0.0, 0.0};
>>>   double p1[3] = {0.0, 1.0, 0.0};
>>>
>>>   // Create a vtkPoints object and store the points in it
>>>   vtkSmartPointer<vtkPoints> pts =
>>>     vtkSmartPointer<vtkPoints>::New();
>>>   pts->InsertNextPoint(origin);
>>>   pts->InsertNextPoint(p0);
>>>   pts->InsertNextPoint(p1);
>>>
>>>   // Setup two colors - one for each line
>>>   unsigned char red[3] = {255, 0, 0};
>>>   unsigned char green[3] = {0, 255, 0};
>>>
>>>   // Setup the colors array
>>>   vtkSmartPointer<vtkUnsignedCharArray> colors =
>>>     vtkSmartPointer<vtkUnsignedCharArray>::New();
>>>   colors->SetNumberOfComponents(3);
>>>   colors->SetName("Colors");
>>>
>>>   // Add the colors we created to the colors array
>>>   colors->InsertNextTupleValue(red);
>>>   colors->InsertNextTupleValue(green);
>>>
>>>   // Create the first line (between Origin and P0)
>>>   vtkSmartPointer<vtkLine> line0 =
>>>     vtkSmartPointer<vtkLine>::New();
>>>   line0->GetPointIds()->SetId(0,0); //the second 0 is the index of the
>>> Origin in the vtkPoints
>>>   line0->GetPointIds()->SetId(1,1); //the second 1 is the index of P0 in
>>> the vtkPoints
>>>
>>>   // Create the second line (between Origin and P1)
>>>   vtkSmartPointer<vtkLine> line1 =
>>>     vtkSmartPointer<vtkLine>::New();
>>>   line1->GetPointIds()->SetId(0,0); //the second 0 is the index of the
>>> Origin in the vtkPoints
>>>   line1->GetPointIds()->SetId(1,2); //2 is the index of P1 in the
>>> vtkPoints
>>>
>>>   // Create a cell array to store the lines in and add the lines to it
>>>   vtkSmartPointer<vtkCellArray> lines =
>>>     vtkSmartPointer<vtkCellArray>::New();
>>>   lines->InsertNextCell(line0);
>>>   lines->InsertNextCell(line1);
>>>
>>>   // Create a polydata to store everything in
>>>   vtkSmartPointer<vtkPolyData> linesPolyData =
>>>     vtkSmartPointer<vtkPolyData>::New();
>>>
>>>   // Add the points to the dataset
>>>   linesPolyData->SetPoints(pts);
>>>
>>>   // Add the lines to the dataset
>>>   linesPolyData->SetLines(lines);
>>>
>>>   // Color the lines - associate the first component (red) of the
>>>   // colors array with the first component of the cell array (line 0)
>>>   // and the second component (green) of the colors array with the
>>>   // second component of the cell array (line 1)
>>>   linesPolyData->GetCellData()->SetScalars(colors);
>>>
>>>   // Visualize
>>>   vtkSmartPointer<vtkPolyDataMapper> mapper =
>>>     vtkSmartPointer<vtkPolyDataMapper>::New();
>>> #if VTK_MAJOR_VERSION <= 5
>>>   mapper->SetInput(linesPolyData);
>>> #else
>>>   mapper->SetInputData(linesPolyData);
>>> #endif
>>>
>>>   vtkSmartPointer<vtkActor> actor =
>>>     vtkSmartPointer<vtkActor>::New();
>>>   actor->SetMapper(mapper);
>>>
>>>   vtkSmartPointer<myMapper> mapperGL =
>>>     vtkSmartPointer<myMapper>::New();
>>>
>>>
>>>   vtkSmartPointer<vtkActor> actorGL =
>>>     vtkSmartPointer<vtkActor>::New();
>>>   actorGL->SetMapper(mapperGL);
>>>
>>>   vtkSmartPointer<vtkRenderer> renderer =
>>>     vtkSmartPointer<vtkRenderer>::New();
>>>   vtkSmartPointer<vtkRenderWindow> renderWindow =
>>>     vtkSmartPointer<vtkRenderWindow>::New();
>>>   renderWindow->AddRenderer(renderer);
>>>   vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
>>>       vtkSmartPointer<vtkRenderWindowInteractor>::New();
>>>   renderWindowInteractor->SetRenderWindow(renderWindow);
>>>   renderer->AddActor(actor);
>>>   renderer->AddActor(actorGL);
>>>
>>>   renderWindow->Render();
>>>   renderWindowInteractor->Start();
>>>
>>>   return EXIT_SUCCESS;
>>> }
>>>
>>>
>>>
>>> when I run the above code, I see the vtk lines but the OpenGL lines are
>>> missing and no output is printed in the console signaling that the code is
>>> being called.
>>>
>>>
>>> thanks for your time
>>>
>>>
>>>
>>>
>>> On Wed, Apr 1, 2015 at 3:23 PM, Aashish Chaudhary <
>>> aashish.chaudhary at kitware.com> wrote:
>>>
>>>> It's much harder In OpenGL backend because of the architecture. If you
>>>> can provide more detail on exactly what you did, we could probably help. I
>>>> would suggest switching to OpenGL2 backend.
>>>>
>>>> - Aashish
>>>>
>>>> On Wed, Apr 1, 2015 at 4:33 AM, Sergio Vera <sergio.vera at alma3d.com>
>>>> wrote:
>>>>
>>>>>
>>>>> I'm using the OpenGL backend since I'm using vtk5.10 (CTK
>>>>> compatibility)
>>>>>
>>>>> On Tue, Mar 31, 2015 at 6:38 PM, Aashish Chaudhary <
>>>>> aashish.chaudhary at kitware.com> wrote:
>>>>>
>>>>>> Are using OpenGL2 or OpenGL backend?
>>>>>>
>>>>>> On Tue, Mar 31, 2015 at 12:13 PM, Sergio Vera <sergio.vera at alma3d.com
>>>>>> > wrote:
>>>>>>
>>>>>>> Thanks,
>>>>>>> I've derived from vtkOpenGLPolyDataMapper, attached the mapper to an
>>>>>>> ordinary actor and added the actor to the renderer.
>>>>>>> It seems that neigher Draw() nor RenderPiece() methods of the mapper
>>>>>>> are being called and  my simple gl code snipped is not being rendered.
>>>>>>>
>>>>>>> Any additional hints?
>>>>>>>
>>>>>>> Thanks in advance
>>>>>>>
>>>>>>> On Tue, Mar 31, 2015 at 4:15 PM, Aashish Chaudhary <
>>>>>>> aashish.chaudhary at kitware.com> wrote:
>>>>>>>
>>>>>>>> there is no easy way. You will have to write your own
>>>>>>>> mapper.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Tue, Mar 31, 2015 at 7:17 AM, Sergio Vera <
>>>>>>>> sergio.vera at alma3d.com> wrote:
>>>>>>>>
>>>>>>>>>
>>>>>>>>> Hello vtk Users
>>>>>>>>>
>>>>>>>>> I'm trying to insert opengl calls inside vtk. So far I have seen
>>>>>>>>> examples of the opposite, insert vtk into opengl.
>>>>>>>>>
>>>>>>>>> There is the suggestion somewhere on the list of using the render
>>>>>>>>> methods of vtkMapper or vtkprops but no definite example
>>>>>>>>>
>>>>>>>>> Where is the best way to do it?
>>>>>>>>>
>>>>>>>>> thanks in advance
>>>>>>>>> --
>>>>>>>>> Sergio Vera
>>>>>>>>>
>>>>>>>>>  Alma IT Systems
>>>>>>>>>  C/ Vilana, 4B, 4º 1ª
>>>>>>>>>  08022 Barcelona
>>>>>>>>>  T. (+34) 932 380 592
>>>>>>>>>  www.alma3d.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
>>>>>>>>>
>>>>>>>>> Search the list archives at:
>>>>>>>>> http://markmail.org/search/?q=vtkusers
>>>>>>>>>
>>>>>>>>> Follow this link to subscribe/unsubscribe:
>>>>>>>>> http://public.kitware.com/mailman/listinfo/vtkusers
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> *| Aashish Chaudhary | Technical Leader         | Kitware Inc.
>>>>>>>>       *
>>>>>>>> *| http://www.kitware.com/company/team/chaudhary.html
>>>>>>>> <http://www.kitware.com/company/team/chaudhary.html>*
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> Sergio Vera
>>>>>>>
>>>>>>>  Alma IT Systems
>>>>>>>  C/ Vilana, 4B, 4º 1ª
>>>>>>>  08022 Barcelona
>>>>>>>  T. (+34) 932 380 592
>>>>>>>  www.alma3d.com
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>>
>>>>>>
>>>>>>
>>>>>> *| Aashish Chaudhary | Technical Leader         | Kitware Inc.
>>>>>>     *
>>>>>> *| http://www.kitware.com/company/team/chaudhary.html
>>>>>> <http://www.kitware.com/company/team/chaudhary.html>*
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Sergio Vera
>>>>>
>>>>>  Alma IT Systems
>>>>>  C/ Vilana, 4B, 4º 1ª
>>>>>  08022 Barcelona
>>>>>  T. (+34) 932 380 592
>>>>>  www.alma3d.com
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>>
>>>>
>>>>
>>>> *| Aashish Chaudhary | Technical Leader         | Kitware Inc.
>>>>   *
>>>> *| http://www.kitware.com/company/team/chaudhary.html
>>>> <http://www.kitware.com/company/team/chaudhary.html>*
>>>>
>>>
>>>
>>>
>>> --
>>> Sergio Vera
>>>
>>>  Alma IT Systems
>>>  C/ Vilana, 4B, 4º 1ª
>>>  08022 Barcelona
>>>  T. (+34) 932 380 592
>>>  www.alma3d.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
>>>
>>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://public.kitware.com/mailman/listinfo/vtkusers
>>>
>>>
>>
>
>
> --
> Sergio Vera
>
>  Alma IT Systems
>  C/ Vilana, 4B, 4º 1ª
>  08022 Barcelona
>  T. (+34) 932 380 592
>  www.alma3d.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150410/f4522913/attachment.html>


More information about the vtkusers mailing list