[vtkusers] how to retrieve mesh's cells of Area(node) in an octree!!!!

cerina cerine-baratelli at hotmail.fr
Thu Aug 30 02:55:58 EDT 2012


Good morning, 
I'm trying to use the vtkOctree in order to subdivide my mesh to many areas.
I modify the vtkOctree file in order to have just 8 areas in my mesh. Now, i
want to retieve all cells and points  and edges that are in the same area (
node), in order to construct a mesh for every area and apply some treatement
on them.
 Is there any body who can help me in Octree, here is the vtkOctree.cxx file
which i modify it:
 #include <vector>

#include <vtkObjectFactory.h>
#include "vtkOctree.h" 
#include "RenderWindow.h" 

class Node 
{ 
public: 
        int NumberOfPoints; 
        int Children[2][2][2]; 
        
        double Center[3]; 
        double Radius[3]; 
        
        bool HasChildren() 
        { 
                return (this->Children[0][0][0]!=-1); 
        }; 
        
        bool NeedsSplit() 
        { 
                return (this->NumberOfPoints>1); 
        }; 
        
        void Reset() 
        { 
                NumberOfPoints=0; 
                Children[0][0][0]=-1; 
        }; 
        
        Node() 
        { 
                this->Reset(); 
        }; 
        
        ~Node() 
        {}; 
}; 


void vtkOctree::Decompose() 
{ 
// vtkSurface *Edges=vtkSurface::New(); 
        
        RenderWindow *Window=RenderWindow::New(); 
        Window->SetInput(this->Input); 
        
        vtkIntArray *PointsNode=vtkIntArray::New(); 
        PointsNode->SetNumberOfValues(this->Input->GetNumberOfPoints()); 
        
        std::vector<Node> Nodes; 
        
        Node Node1; 
        
        double Bounds[6]; 
        
        this->Input->GetPoints()->ComputeBounds(); 
        this->Input->GetPoints()->GetBounds(Bounds); 
        
        // Create Root Node and push it into the array of nodes 
        Node1.NumberOfPoints=this->Input->GetNumberOfPoints(); 
        // subdivide the Mesh to 8 areas 
        for (int i=0;i<3;i++) 
        { 
                Node1.Center[i]=0.5*(Bounds[2*i+1]+Bounds[2*i]); 
                Node1.Radius[i]=0.5*(Bounds[2*i+1]-Bounds[2*i]); 
        } 
        Nodes.push_back(Node1); 
        
        // Assign all points to root node 
        for (int i=0;i<this->Input->GetNumberOfPoints();i++) 
                PointsNode->SetValue(i,0); 
        
        int NumberOfSplitNodes; 
        int Level=0; 
        for(int h=0;h<2; h++) 
        { 
                cout<<"Level "<<Level++&lt;&lt;endl; 
                NumberOfSplitNodes=0; 
                for (int i=0;i&lt;this->Input->GetNumberOfPoints();i++) 
                { 
                        int NodeId=PointsNode->GetValue(i); 
                        if (Nodes[NodeId].NeedsSplit()) 
                        { 
                                if (!Nodes[NodeId].HasChildren()) 
                                { 
                                        NumberOfSplitNodes++; 
                                        // we need to create 8 sub-nodes
(one for each octant)
                                         int Coordinates[3]; 
                                        for
(Coordinates[0]=0;Coordinates[0]<2;Coordinates[0]++)
                                         { 
                                                for
(Coordinates[1]=0;Coordinates[1]<2;Coordinates[1]++)
                                                 { 
                                                        for
(Coordinates[2]=0;Coordinates[2]<2;Coordinates[2]++)
                                                         { 
                                                               
Node1.Reset(); 
                                                                // Create
one child node
                                                                 for (int
j=0;j<3;j++)
                                                                 { 
                                                                       
Node1.Center[j]=Nodes[NodeId].Center[j]+
                                                                                
((double) Coordinates[j]-0.5)*Nodes[NodeId].Radius[j];
                                                                        
Node1.Radius[j]=0.5*Nodes[NodeId].Radius[j];
 


                                                                } 
                                                                
                                                               
Nodes[NodeId].Children[Coordinates[0]][Coordinates[1]][Coordinates[2]]=
                                                                        
Nodes.size();
                                                                
Nodes.push_back(Node1);
                                                         } 
                                                } 
                                        } 
                                } 
                                double Point[3]; 
                                this->Input->GetPoint(i,Point); 
                                int Coordinates[3]; 
                                for (int j=0;j<3;j++) 
                                { 
                                        if
(Point[j]<Nodes[NodeId].Center[j]) 
                                                Coordinates[j]=0; 
                                        else 
                                                Coordinates[j]=1; 
                                } 
                                int
Child=Nodes[NodeId].Children[Coordinates[0]][Coordinates[1]][Coordinates[2]];
                                 PointsNode->SetValue(i,Child); 
                                Nodes[Child].NumberOfPoints++; 
                                
                                cout<<" la region du sommet "<< i <<"est"<<
PointsNode->GetValue(i)<<endl;
                 } 
                } 
                h++; 
        }; 

                // create polydata for visualization 

                cout&lt;&lt;NumberOfSplitNodes&lt;&lt;&quot; Nodes
split&quot;&lt;&lt;endl; 
                Window->DisplayVerticesColors(PointsNode); 
                Window->Render(); 
                Window->Interact(); 
        
        Window->Delete(); 
        PointsNode->Delete(); 
} 

void vtkOctree::SetInput(vtkSurface *Input) 
{ 
        if (this->Input) 
                this->Input->UnRegister(this); 
        
        Input->Register(this); 
        this->Input=Input; 
} 

vtkOctree * 
vtkOctree::New () 
{ 
        // First try to create the object from the vtkObjectFactory 
        vtkObject *ret = vtkObjectFactory::CreateInstance ("vtkOctree"); 
        if (ret) 
        { 
                return (vtkOctree *) ret; 
        } 
        // If the factory was unable to create the object, then create it
here. 
        return (new vtkOctree); 

} 

vtkOctree::vtkOctree() 
{ 
        this->Input=0; 
} 

vtkOctree::~vtkOctree() 
{ 
        if (this->Input) 
                this->Input->UnRegister(this); 
} 
and the Octree.cxx in which there is the main: 

#include "vtkSurface.h" 
#include "RenderWindow.h" 
#include "vtkOctree.h" 

int main( int argc, char *argv[] ) 
{ 
         // Parse command line arguments 
  if(argc != 2) 
    { 
    std::cout << "Usage: " << argv[0] << " Filename(.ply)" << std::endl; 
    return EXIT_FAILURE; 
    } 

        vtkSurface *Mesh; 
        
        // Load the mesh and create the vtkSurface data structure 
        Mesh=vtkSurface::New(); 
        cout <<"load : "<<argv[1]&lt;&lt;endl; 
        Mesh->CreateFromFile(argv[1]); 

        // prints to standard output the mesh caracteristics 
        Mesh->DisplayMeshProperties(); 
        
        vtkOctree *Octree=vtkOctree::New(); 
        Octree->SetInput(Mesh); 
        Octree->Decompose(); 

        return (0); 
} 
Best regards, 
Cerina 





--
View this message in context: http://vtk.1045678.n5.nabble.com/how-to-retrieve-mesh-s-cells-of-Area-node-in-an-octree-tp5715677.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list