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

Gishara Indeewarie gish.777 at gmail.com
Thu Feb 9 04:21:56 EST 2012


Hi David,

I saw that in the example (
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/MoveActor ) if we
did not set the center of the objects only one object is shown. I want to
show the two objects according to their natural coordinates that keeps the
natural shape of the object which is formed by the added objects. The
screenshots of the object I got and the object I want is attached herewith.
The code I used is similar to the one in the example except I did not set
any center.
Please give me your ideas.

Thanks.

On Thu, Feb 9, 2012 at 9:21 AM, Gishara Indeewarie <gish.777 at gmail.com>wrote:

> 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
>



-- 
Gish
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120209/98d67cc3/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: objects.jpg
Type: image/jpeg
Size: 66901 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120209/98d67cc3/attachment.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: points.jpg
Type: image/jpeg
Size: 66684 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120209/98d67cc3/attachment-0001.jpg>


More information about the vtkusers mailing list