Bonsoir,

j'ai eu un code d'octree que je l'ai modifié un peu à l'aide de mon ami. Maintenant, j'ai utilisé cet octree pour segmenter un objet 3D en un ensemble des regions. Après ça, je me bloque. Le problème est que je veux recuperer, pour chaque noeud de l'octree, la liste des faces de mon objet 3D (maillage 3D) qui y appatient pour les sauvegarder dans un fichier, Mais j'ai pas reussi à connaitre comment se localiser sur un noeud et recuperer tous ses faces. Bon,j'ai essayer de parcourir les faces de mon objet et verifier pour chaque face si elle appartient au noeud courant ou nn, et les stocker dans un liste, mais, lorsque j'essaye de generer un fichier PLY à partir de cette liste, le fichier est illisible avec son contenu . Un peu d'aide SVP .
Ceci est mon code ( bon j'utilise la bibliothèque vtk, mais elle utilise le langage c++ aussi ):
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#include <vtkSelectionNode.h>
#include <vtkSelection.h>
#include <vtkExtractSelection.h>
#include <vtkSmartPointer.h>
#include <vtkIdTypeArray.h>
#include <vtkUnstructuredGrid.h>
#include <vtkDataSetSurfaceFilter.h>
 
#include <vector>
#include <iostream>
#include <vtkObjectFactory.h>
#include "vtkOctree.h"
#include "RenderWindow.h"
 
#include <fstream>
using namespace std; 
#include <string.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++<<endl;
		NumberOfSplitNodes=0;
		for (int i=0;i<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++;
 
 
 
		}
 
 
		}
		h++;
};
 
		// create polydata for visualization
 
		cout<<NumberOfSplitNodes<<" Nodes split"<<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);
 
}
Merci