[vtkusers] Problem with showing two surfaces in the same window - VTK

Gishara Indeewarie gish.777 at gmail.com
Wed Feb 8 22:51:08 EST 2012


Thanks David. I fixed my problem by adding two actors to the same renderer
as per the example. (I was adding two renderers  before) Thanks again.

On Wed, Feb 8, 2012 at 6:01 PM, David Doria <daviddoria at gmail.com> wrote:

> On Wed, Feb 8, 2012 at 5:21 AM, Gishara Indeewarie <gish.777 at gmail.com>
> wrote:
> > Hi all,
> >
> > I want to add two surfaces in to a same window. But when I add the second
> > surface the first surface can't be seen. It worked well when I viewed
> only
> > the points without creating the surfaces.
> > I have managed to show the two surfaces but in different viewports, but I
> > want to show it in the same where the user can view the relevant
> positions
> > of the surfaces.
> > The code I have done so far is given below.
> >
> > vtkPoints *points = newPts;//ReadCFDData2();
> >  vtkPoints *suction_points = newPtsSuction;
> >
> >   vtkSmartPointer<vtkPolyData> polydata =
> > vtkSmartPointer<vtkPolyData>::New();
> >   polydata->SetPoints(points);
> >
> >   vtkSmartPointer<vtkPolyData> suction_polydata =
> > vtkSmartPointer<vtkPolyData>::New();
> >   suction_polydata->SetPoints(suction_points);
> >
> >   vtkSmartPointer<vtkDoubleArray> weights =
> > vtkSmartPointer<vtkDoubleArray>::New();
> >   weights->SetNumberOfValues(PoValues.GetSize());
> >   for(int i=0; i< PoValues.GetSize();i++){
> >   weights->SetValue(i, PoValues[i]);
> >   }
> >
> >
> >   vtkSmartPointer<vtkDoubleArray> suction_weights =
> > vtkSmartPointer<vtkDoubleArray>::New();
> >   suction_weights->SetNumberOfValues(PoValuesSuction.GetSize());
> >   for(int i=0; i< PoValuesSuction.GetSize();i++){
> >   suction_weights->SetValue(i, PoValuesSuction[i]);
> >   }
> >
> >
> >   vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =
> > vtkSmartPointer<vtkVertexGlyphFilter>::New();
> >   glyphFilter->SetInputConnection(polydata->GetProducerPort());
> >   glyphFilter->Update();
> >
> >   vtkSmartPointer<vtkVertexGlyphFilter> suction_glyphFilter =
> > vtkSmartPointer<vtkVertexGlyphFilter>::New();
> >
> >
> suction_glyphFilter->SetInputConnection(suction_polydata->GetProducerPort());
> >   suction_glyphFilter->Update();
> >
> >   // Create a plane
> >  // vtkSmartPointer<vtkPlane> plane = vtkSmartPointer<vtkPlane>::New();
> >   //plane->SetOrigin(polydata->GetCenter());
> >   //plane->SetNormal(1,1,1);
> >
> >
> >   // Construct the surface and create isosurface.
> >   vtkSmartPointer<vtkSurfaceReconstructionFilter> surf =
> > vtkSmartPointer<vtkSurfaceReconstructionFilter>::New();
> >
> >   surf->SetInput(polydata);
> >  //
> >   vtkSmartPointer<vtkContourFilter> cf =
> >  vtkSmartPointer<vtkContourFilter>::New();
> >   cf->SetInputConnection(surf->GetOutputPort());
> >   cf->Update();
> >
> >   // Construct the suction blade surface and create isosurface.
> >   vtkSmartPointer<vtkSurfaceReconstructionFilter> suction_surf =
> > vtkSmartPointer<vtkSurfaceReconstructionFilter>::New();
> >
> >   suction_surf->SetInput(suction_polydata);
> >  //
> >   vtkSmartPointer<vtkContourFilter> suction_cf =
> >  vtkSmartPointer<vtkContourFilter>::New();
> >   suction_cf->SetInputConnection(suction_surf->GetOutputPort());
> >   suction_cf->Update();
> >
> >  vtkPolyData* outputPolyData = cf->GetOutput();
> >  vtkPolyData* suction_outputPolyData = suction_cf->GetOutput();
> >
> >   //double bounds[6];
> >   //outputPolyData->GetBounds(bounds);
> >
> >   // Find min and max z
> >  // double minz = bounds[4];
> >  // double maxz = bounds[5];
> >
> >
> >   // Create the color map
> >   vtkSmartPointer<vtkLookupTable> colorLookupTable =
> > vtkSmartPointer<vtkLookupTable>::New();
> > colorLookupTable->SetHueRange(0.667,0.0);
> > colorLookupTable->SetNumberOfColors(16);
> >
> >  // colorLookupTable->SetTableRange(minz, maxz);
> >
> >   colorLookupTable->Build();
> >
> >   // Create the color map
> >   vtkSmartPointer<vtkLookupTable> colorLookupTable_s =
> > vtkSmartPointer<vtkLookupTable>::New();
> > colorLookupTable_s->SetHueRange(0.667,0.0);
> > colorLookupTable_s->SetNumberOfColors(16);
> >
> >  // colorLookupTable->SetTableRange(minz, maxz);
> >
> >   colorLookupTable_s->Build();
> >
> >   // Generate the colors for each point based on the color map
> > /*  vtkSmartPointer<vtkUnsignedCharArray> colors =
> >     vtkSmartPointer<vtkUnsignedCharArray>::New();
> >   colors->SetNumberOfComponents(3);
> >   colors->SetName("Colors");
> >   for(int i = 0; i < outputPolyData->GetNumberOfPoints(); i++)
> >     {
> >     double p[3];
> >     outputPolyData->GetPoint(i,p);
> >
> >     double dcolor[3];
> >     colorLookupTable->GetColor(PoValues[i], dcolor);
> >     unsigned char color[3];
> >     for(unsigned int j = 0; j < 3; j++)
> >       {
> >       color[j] = static_cast<unsigned char>(255.0 * dcolor[j]);
> >       }
> >
> >     colors->InsertNextTupleValue(color);
> >     }
> >
> >   outputPolyData->GetPointData()->SetScalars(colors);*/
> >  // double min = minimumValue(PoValues);
> >      int length = PoValues.GetSize();// establish size of array
> >      double max = PoValues[0];       // start with max = first element
> >
> >      for(int i = 1; i<length; i++)
> >      {
> >           if(PoValues[i] > max)
> >                 max = PoValues[i];
> >      }
> >
> > double min = PoValues[0];
> >
> > for(int i = 1; i<length; i++)
> >      {
> >           if(PoValues[i] < min)
> >                 min = PoValues[i];
> >      }
> >
> >
> >   colorLookupTable->SetTableRange( min,max);
> >   outputPolyData->GetPointData()->SetScalars(weights);
> >
> >   int length_s = PoValuesSuction.GetSize();// establish size of array
> >      double max_s = PoValuesSuction[0];       // start with max = first
> > element
> >
> >      for(int i = 1; i<length_s; i++)
> >      {
> >           if(PoValuesSuction[i] > max_s)
> >                 max_s = PoValuesSuction[i];
> >      }
> >
> > double min_s = PoValuesSuction[0];
> >
> > for(int i = 1; i<length_s; i++)
> >      {
> >           if(PoValuesSuction[i] < min_s)
> >                 min_s = PoValuesSuction[i];
> >      }
> >
> >
> >   colorLookupTable_s->SetTableRange( min_s,max_s);
> >   suction_outputPolyData->GetPointData()->SetScalars(suction_weights);
> >
> >   // Create a mapper and actor
> >   vtkSmartPointer<vtkPolyDataMapper> mapper =
> > vtkSmartPointer<vtkPolyDataMapper>::New();
> >
> >
> mapper->SetInputConnection(/*reverse->GetOutputPort()*/cf->GetOutputPort());
> >  mapper->ScalarVisibilityOn();
> >   mapper->SetColorModeToMapScalars();
> >   mapper->SetLookupTable(colorLookupTable);
> >   mapper->SetScalarMaterialModeToDefault();
> >  mapper->SetScalarRange(min,max);
> >   vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
> >    //actor->GetProperty()->SetColor(1.0, 0.8941, 0.7686); // bisque
> >   actor->SetMapper(mapper);
> >
> >
> >   // Create a mapper and actor for suction blade
> >   vtkSmartPointer<vtkPolyDataMapper> suction_mapper =
> > vtkSmartPointer<vtkPolyDataMapper>::New();
> >
> >
> suction_mapper->SetInputConnection(/*reverse->GetOutputPort()*/suction_cf->GetOutputPort());
> >  suction_mapper->ScalarVisibilityOn();
> >   suction_mapper->SetColorModeToMapScalars();
> >   suction_mapper->SetLookupTable(colorLookupTable_s);
> >   suction_mapper->SetScalarMaterialModeToDefault();
> >  suction_mapper->SetScalarRange(min_s,max_s);
> >   vtkSmartPointer<vtkActor> suction_actor =
> > vtkSmartPointer<vtkActor>::New();
> >  //  actor->GetProperty()->SetColor(1.0, 0.8941, 0.7686); // bisque
> >   suction_actor->SetMapper(suction_mapper);
> >
> >   //Create a renderer, render window, and interactor
> >   vtkSmartPointer<vtkRenderer> renderer =
> > vtkSmartPointer<vtkRenderer>::New();
> >   renderer->SetViewport( 0., 0., 0.5, 1. );
> >   renderer->SetBackground( 0.2, 0.2, 0.8 );
> >
> >   vtkSmartPointer<vtkRenderer> suction_renderer =
> > vtkSmartPointer<vtkRenderer>::New();
> >   suction_renderer->SetViewport( 0.5, 0., 1., 1. );
> >   suction_renderer->SetBackground( 0.8, 0.2, 0.2 );
> >
> >
> >   vtkSmartPointer<vtkRenderWindow> renderWindow =
> > vtkSmartPointer<vtkRenderWindow>::New();
> >   renderWindow->AddRenderer(renderer);
> >   renderWindow->AddRenderer(suction_renderer);
> >   vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
> > vtkSmartPointer<vtkRenderWindowInteractor>::New();
> >   renderWindowInteractor->SetRenderWindow(renderWindow);
> >
> >  // vtkSmartPointer<vtkRenderWindowInteractor> interactor =
> > vtkSmartPointer<vtkRenderWindowInteractor>::New();
> >   //interactor->SetRenderWindow( renderWindow );
> >   //Add the actor to the scene
> >   renderer->AddViewProp(actor);
> >   suction_renderer->AddViewProp(suction_actor);
> >  // renderer->SetBackground(.1, .6, .3); // Background color green
> >
> >   //Render and interact
> >   renderWindow->Render();
> >   renderWindowInteractor->Start();
> >
> > Please give me your ideas.
> > Thanks.
> > --
> > Gish
>
> Please create an as-simple-as-possible example of what you are trying to
> do.
>
> From your actual question, it sounds like you just want to add two
> objects to a scene. You seem to be doing it correctly at a glance, but
> convince yourself using a short, compilable example like this:
>
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/MoveActor
>
> I would start from something like that and gradually add back in the
> rest of your code (i.e. the surface creation, coloring, etc) and see
> when you don't get what you'd expect. Then you can ask a succinct
> question and hopefully we can help.
>
> David
>



-- 
Gish
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120209/d2ff3c8c/attachment.htm>


More information about the vtkusers mailing list