[vtkusers] Pointers to vtkSmartPointers ?

mandalin mandalin147 at gmail.com
Sat Nov 12 13:33:14 EST 2011


*
The following code is giving an error when I try to render the scene, an
error that I do not get when I use vtkUnstructruedGrid instead of
vtkPolyData. I am wondering if it is because of the way I am handeling
pointers to pointers. 
   

Let's say I've got a number of polygons, the examples of the API for
PolyData are all for a single polygon. I have generalized it as follows.
Notice, I am not using smart pointers. However, I am forced to use
=vtkPolygon::New(); instead of the =new vtkPolygon; 

Is this the appropriate/best way to input many polygons into vtkCellData
into vtkPolyData ? 

The code work well until I render, at which point it has an error upon the
call some square root member function...

*


 //Make the Polygons

        vtkPolygon** polygons;
        polygons=new vtkPolygon *[NumWalls];      
        
        for(int wallind=0; wallind<NumWalls; wallind++)
        {   

            polygons[wallind]= vtkPolygon::New();
            polygons[wallind]->GetPointIds()->SetNumberOfIds(
walls[wallind].corners.size() ); //make a quad

            
            for(int cornerind=0; cornerind<walls[wallind].corners.size();
cornerind++)
            {   
                polygons[wallind]->GetPointIds()->SetId(cornerind,
walls[wallind].corner_indices[cornerind]);
                
            }
            
        }
*
The complete code block that I am using is below *

  
    //Store the positions of the vertices
    
        vtkSmartPointer<vtkPoints> GeometryVertices =
vtkSmartPointer<vtkPoints>::New();
        
        GeometryVertices->Allocate(NumVertices);
        
        for(int i=0; i<NumVertices; i++)
        { 
            GeometryVertices->InsertPoint(i, unique_corners[i].x,
unique_corners[i].y, unique_corners[i].z);
        }
        
    //Makeing an array of ID's for each polygon
        vtkIdList** pointIDs;
        pointIDs= new vtkIdList *[NumWalls];
        
        int cornersperwall;
        
        for(int wallind=0; wallind<NumWalls; wallind++)
        {   cornersperwall=walls[wallind].corners.size();
            // std::cout&lt;&lt;&quot;Corners in this wall
&quot;&lt;&lt;cornersperwall&lt;&lt;std::endl;
            pointIDs[wallind]= vtkIdList::New();
            
            for(int cornerind=0; cornerind&lt;walls[wallind].corners.size();
cornerind++)
            {  
               
pointIDs[wallind]->InsertNextId(walls[wallind].corner_indices[cornerind]);
            }
        }
        
    
    //Make the Polygons
        vtkPolygon** polygons;
        polygons=new vtkPolygon *[NumWalls];      
        
        for(int wallind=0; wallind<NumWalls; wallind++)
        {   

            polygons[wallind]= vtkPolygon::New();
            polygons[wallind]->GetPointIds()->SetNumberOfIds(
walls[wallind].corners.size() ); //make a quad

            
            for(int cornerind=0; cornerind<walls[wallind].corners.size();
cornerind++)
            {   
                polygons[wallind]->GetPointIds()->SetId(cornerind,
walls[wallind].corner_indices[cornerind]);
                
            }
            
        }
        
    // Create a PolyData
    vtkSmartPointer<vtkCellArray> PolygonCellArray =
vtkSmartPointer<vtkCellArray>::New();
    vtkSmartPointer<vtkPolyData> PolygonPolyData =
vtkSmartPointer<vtkPolyData>::New();
    
    for(int wallind=0; wallind<NumWalls; wallind++)
    {   
        PolygonCellArray -> InsertNextCell(polygons[wallind]);
    }
    
    PolygonPolyData->SetPoints(GeometryVertices);
    PolygonPolyData->SetPolys(PolygonCellArray);
        
    
    // Create a mapper and actor
    vtkSmartPointer<vtkPolyDataMapper> mapper =
    vtkSmartPointer<vtkPolyDataMapper>::New();
    mapper->SetInput(PolygonPolyData);
    
    vtkSmartPointer<vtkActor> actor =
    vtkSmartPointer<vtkActor>::New();
    actor->SetMapper(mapper);
    
    // Visualize
    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);
   
    renderWindow->Render();
    renderWindowInteractor->Start();
    
    
    return;

--
View this message in context: http://vtk.1045678.n5.nabble.com/Pointers-to-vtkSmartPointers-tp4987399p4987399.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list