]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.opencascade.vtk/src/org/simantics/opencascade/vtk/VTKOCCTool.java
vtk 8.2.0 API changes
[simantics/3d.git] / org.simantics.opencascade.vtk / src / org / simantics / opencascade / vtk / VTKOCCTool.java
1 /*******************************************************************************
2  * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
3  * Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.opencascade.vtk;
13
14 import java.util.List;
15
16 import javax.vecmath.Matrix4d;
17 import javax.vecmath.Point3d;
18
19 import org.jcae.opencascade.jni.BRepMesh_IncrementalMesh;
20 import org.jcae.opencascade.jni.BRep_Tool;
21 import org.jcae.opencascade.jni.GP_Trsf;
22 import org.jcae.opencascade.jni.Poly_Triangulation;
23 import org.jcae.opencascade.jni.TopAbs_Orientation;
24 import org.jcae.opencascade.jni.TopAbs_ShapeEnum;
25 import org.jcae.opencascade.jni.TopExp_Explorer;
26 import org.jcae.opencascade.jni.TopLoc_Location;
27 import org.jcae.opencascade.jni.TopoDS_Face;
28 import org.jcae.opencascade.jni.TopoDS_Shape;
29 import org.simantics.opencascade.OCCTTool;
30
31 import vtk.vtkActor;
32 import vtk.vtkAlgorithmOutput;
33 import vtk.vtkAppendPolyData;
34 import vtk.vtkAssembly;
35 import vtk.vtkCleanPolyData;
36 import vtk.vtkDataSetMapper;
37 import vtk.vtkFeatureEdges;
38 import vtk.vtkGlyph3D;
39 import vtk.vtkIdList;
40 import vtk.vtkPoints;
41 import vtk.vtkPolyData;
42 import vtk.vtkPolyDataMapper;
43 import vtk.vtkPolyDataNormals;
44 import vtk.vtkProp;
45 import vtk.vtkPropCollection;
46 import vtk.vtkProperty;
47 import vtk.vtkSphereSource;
48 import vtk.vtkTriangle;
49
50 public class VTKOCCTool {
51         public static vtkAssembly vtkTestAssembly() {
52                 vtkAssembly assemblies = new vtkAssembly();
53                 vtkPolyData partGrid = createTestPartGrid();
54                 gridToAssembly(assemblies, partGrid);
55                 return assemblies;
56         }
57         
58         public static vtkAssembly vtkOCCShapeToAssembly(TopoDS_Shape shape) {
59                 double deflection = 0.001;
60
61                 if (deflection <= 0.0) {
62                         deflection = 0.0005;
63                         System.out.println("Bad value for deflection. Using: " + deflection);
64                 }
65
66                 // FIXME : leaks memory!
67                 //BRepTools.clean(shape);
68
69                 double mass = OCCTTool.getMass(shape);
70
71                 if (mass < 1.0e-12) {
72                         System.out.println("Non 3D-shape detected");
73                         System.out.println("The cad import features are currently limited to 3D models.");
74                 }
75
76                 double length = OCCTTool.getBoundingBoxDiagonal(shape);
77                 deflection *= length; // use relative units
78
79                 BRepMesh_IncrementalMesh mesh = new BRepMesh_IncrementalMesh(shape,deflection);
80
81                 int faceNumber = 0;
82                 TopExp_Explorer expFace = new TopExp_Explorer();
83
84                 vtkAssembly assemblies = new vtkAssembly();
85                 for (expFace.init(shape, TopAbs_ShapeEnum.FACE); expFace.more(); expFace.next()) {
86                         TopoDS_Face face = (TopoDS_Face) expFace.current();
87                         vtkPolyData partGrid = createPartGrid(face);
88                         face.delete();
89                         if (partGrid == null)
90                                 continue;
91                         faceNumber++;
92                         //gridToAssembly(assemblies, partGrid, stlSurfaceData, stlEdgeData);
93                         gridToAssembly(assemblies, partGrid);
94                         
95                 }
96                 expFace.delete();
97                 mesh.delete();
98
99                 if (faceNumber == 0) {
100                         System.out
101                                         .println("Cad import: error: no surface triangulation was generated.");
102                         return null;
103                 }
104
105                 return assemblies;
106         }
107         
108         private static void gridToAssembly(vtkAssembly assemblies, vtkPolyData partGrid, vtkAppendPolyData stlSurfaceData, vtkAppendPolyData stlEdgeData) {
109         
110         double featureAngle = 30;
111
112         
113         vtkDataSetMapper partMapper = new vtkDataSetMapper();
114         
115         boolean computeNormals = true;
116         boolean cleanPart = true;
117         boolean mergePoints = false;
118
119         vtkCleanPolyData partCleaner = new vtkCleanPolyData();       
120         if (cleanPart)
121         {
122             partCleaner.SetInputData(partGrid);
123             if(mergePoints) {
124               partCleaner.PointMergingOn();
125             } else {
126               partCleaner.PointMergingOff();
127             }
128         }
129         
130         if (computeNormals)
131         {
132             vtkPolyDataNormals partNormals = new vtkPolyDataNormals();
133          
134             if (cleanPart)
135             {
136                 partNormals.SetInputConnection(partCleaner.GetOutputPort());
137             }
138             else partNormals.SetInputData(partGrid);
139                 
140             partNormals.SetFeatureAngle(featureAngle); // this do not have to be neccesarily called
141             partMapper.SetInputConnection(partNormals.GetOutputPort());
142             partNormals.Delete();          
143         }
144         else
145         {
146             if (cleanPart) partMapper.SetInputConnection(partCleaner.GetOutputPort()); // metoda 2, ne tak pekne, viz http://www.codeguru.com/cpp/g-m/opengl/article.php/c2681
147             else partMapper.SetInputData(partGrid); // metoda 1, ne tak pekne stinovani, viz: http://www.codeguru.com/cpp/g-m/opengl/article.php/c2681
148         }
149         partMapper.ScalarVisibilityOn();
150         
151         vtkActor partActor = new vtkActor();
152
153         partActor.SetPickable(1);
154         partActor.GetProperty().SetColor(1, 1, 0);
155         partActor.SetMapper(partMapper);
156         
157         // EDGES OF PARTS DETECTION
158         vtkFeatureEdges partEdges = new vtkFeatureEdges();
159         if (cleanPart) partEdges.SetInputConnection(partCleaner.GetOutputPort());
160         else partEdges.SetInputData(partGrid); 
161         partEdges.SetFeatureAngle(featureAngle);  // this do not have to be neccesarily called
162         partEdges.FeatureEdgesOn();
163         partEdges.BoundaryEdgesOn();
164         partEdges.NonManifoldEdgesOn();
165         partEdges.ManifoldEdgesOn();
166
167         vtkDataSetMapper partEdgesMapper = new vtkDataSetMapper();
168         partEdgesMapper.SetInputConnection(partEdges.GetOutputPort());
169         partEdgesMapper.SetResolveCoincidentTopologyToPolygonOffset();
170         partEdgesMapper.ScalarVisibilityOff();
171         
172         vtkActor partEdgesActor = new vtkActor();
173         partEdgesActor.SetPickable(0);
174         partEdgesActor.GetProperty().SetColor(1, 0, 1);
175         partEdgesActor.SetMapper(partEdgesMapper);
176         
177
178         // Add triangles and edges to STL structures:
179         //--------------------------------------------
180         if (cleanPart) stlSurfaceData.AddInputData(partCleaner.GetOutput());
181         else stlSurfaceData.AddInputData(partGrid);
182         stlEdgeData.AddInputData(partEdges.GetOutput());
183                 
184         assemblies.AddPart(partActor);
185         assemblies.AddPart(partEdgesActor);        
186         
187         // Clean up:
188         //----------
189         partEdgesActor.Delete();
190         partEdgesMapper.Delete();
191         partEdges.Delete();
192         partActor.Delete();
193         partMapper.Delete();
194         partGrid.Delete();
195         partCleaner.Delete();
196     }
197
198 public static void gridToAssembly(vtkAssembly assemblies, vtkPolyData partGrid) {
199     
200     double featureAngle = 30;
201
202     
203     vtkDataSetMapper partMapper = new vtkDataSetMapper();
204     
205     boolean computeNormals = true;
206     boolean cleanPart = false;
207     boolean mergePoints = false;
208
209     vtkCleanPolyData partCleaner = new vtkCleanPolyData();       
210     if (cleanPart)
211     {
212         partCleaner.SetInputData(partGrid);
213         if(mergePoints) {
214           partCleaner.PointMergingOn();
215         } else {
216           partCleaner.PointMergingOff();
217         }
218     }
219     
220     if (computeNormals)
221     {
222         vtkPolyDataNormals partNormals = new vtkPolyDataNormals();
223      
224         if (cleanPart)
225         {
226                 vtkAlgorithmOutput out = partCleaner.GetOutputPort();
227             partNormals.SetInputConnection(out);
228             out.Delete();
229         }
230         else partNormals.SetInputData(partGrid);
231             
232         partNormals.SetFeatureAngle(featureAngle); // this do not have to be neccesarily called
233         vtkAlgorithmOutput out = partNormals.GetOutputPort();
234         partMapper.SetInputConnection(out);
235         out.Delete();
236         partNormals.Delete();          
237     }
238     else
239     {
240         if (cleanPart) {
241                 vtkAlgorithmOutput out = partCleaner.GetOutputPort();
242                 partMapper.SetInputConnection(out); // metoda 2, ne tak pekne, viz http://www.codeguru.com/cpp/g-m/opengl/article.php/c2681
243                 out.Delete();
244         }
245         else partMapper.SetInputData(partGrid); // metoda 1, ne tak pekne stinovani, viz: http://www.codeguru.com/cpp/g-m/opengl/article.php/c2681
246     }
247     partMapper.ScalarVisibilityOn();
248     
249     vtkActor partActor = new vtkActor();
250     partActor.SetPickable(1);
251     vtkProperty prop = partActor.GetProperty();
252     prop.SetColor(1, 1, 0);
253     prop.Delete();
254     partActor.SetMapper(partMapper);
255     
256     assemblies.AddPart(partActor);
257     
258     {
259             // EDGES OF PARTS DETECTION
260             vtkFeatureEdges partEdges = new vtkFeatureEdges();
261             if (cleanPart) {
262                 vtkAlgorithmOutput out = partCleaner.GetOutputPort();
263                 partEdges.SetInputConnection(out);
264                 out.Delete();
265             }
266             else partEdges.SetInputData(partGrid); 
267            // partEdges.SetFeatureAngle(featureAngle);  // this do not have to be neccesarily called
268             partEdges.FeatureEdgesOn();
269             partEdges.BoundaryEdgesOn();
270             partEdges.NonManifoldEdgesOn();
271             partEdges.ManifoldEdgesOn();
272         
273             vtkDataSetMapper partEdgesMapper = new vtkDataSetMapper();
274             vtkAlgorithmOutput out = partEdges.GetOutputPort();
275             partEdgesMapper.SetInputConnection(out);
276             out.Delete();
277             partEdgesMapper.SetResolveCoincidentTopologyToPolygonOffset();
278             partEdgesMapper.ScalarVisibilityOff();
279             
280             vtkActor partEdgesActor = new vtkActor();
281            
282             prop = partEdgesActor.GetProperty();
283             prop.SetColor(0, 0, 0);
284             prop.SetLineWidth(2.0);
285             prop.Delete();
286             partEdgesActor.SetMapper(partEdgesMapper);
287             partEdgesActor.PickableOn();  
288             
289             assemblies.AddPart(partEdgesActor);        
290             
291             {
292
293                 EdgePointsFilter edgePoints = new EdgePointsFilter();
294                 
295                  
296                 out = partEdges.GetOutputPort();
297                     edgePoints.SetInputConnection(out);
298                     out.Delete();
299                     
300 //                  vtkDataSetMapper partEdgePointsMapper = new vtkDataSetMapper();
301 //                  out = edgePoints.GetOutputPort();
302 //                  partEdgePointsMapper.SetInputConnection(out);
303 //                  out.Delete();
304                     
305 //                  vtkVertexGlyphFilter glyphFilter = new vtkVertexGlyphFilter();
306 //                  out = edgePoints.GetOutputPort();
307 //                  glyphFilter.SetInputConnection(out);
308 //                  glyphFilter.Update();
309 //                  out.Delete();
310 //                  
311 //                  vtkPolyDataMapper partEdgePointsMapper = new vtkPolyDataMapper();
312 //                  out = glyphFilter.GetOutputPort();
313 //                  partEdgePointsMapper.SetInputConnection(out);
314 //                  out.Delete();
315                     
316                     vtkSphereSource sphereSource = new vtkSphereSource();
317                     vtkGlyph3D glyph3D = new vtkGlyph3D();
318                     out = sphereSource.GetOutputPort();
319                     glyph3D.SetSourceConnection(out);
320                     out.Delete();
321                     
322                     out = edgePoints.GetOutputPort();
323                     glyph3D.SetInputConnection(out);
324                     out.Delete();
325                     
326                     //glyph3D.ScalingOff();
327                     glyph3D.SetScaleFactor(0.03);
328                     
329                     glyph3D.Update();
330                     
331                     vtkPolyDataMapper partEdgePointsMapper = new vtkPolyDataMapper();
332                     out = glyph3D.GetOutputPort();
333                     partEdgePointsMapper.SetInputConnection(out);
334                     out.Delete();
335                     
336                     vtkActor edgePointsActor = new vtkActor();
337                    
338                     prop = edgePointsActor.GetProperty();
339                     prop.SetColor(0, 0, 1);
340                     //prop.SetPointSize(10.0);
341                     //prop.SetRepresentationToPoints();
342                     prop.Delete();
343                     edgePointsActor.SetMapper(partEdgePointsMapper);
344                    
345                     edgePointsActor.PickableOn();
346                     assemblies.AddPart(edgePointsActor);
347                     
348                     
349                     edgePointsActor.Delete();
350                     partEdgePointsMapper.Delete();
351                    // edgePoints.Delete();
352             }
353             // Clean up:
354             //----------
355             partEdgesActor.Delete();
356             partEdgesMapper.Delete();
357             partEdges.Delete();
358     }
359    
360     partActor.Delete();
361     partMapper.Delete();
362     partGrid.Delete();
363     partCleaner.Delete();
364 }
365         
366         
367         
368         public static vtkPolyData createPartGrid ( TopoDS_Face face)
369     {
370         TopLoc_Location Location = new TopLoc_Location();
371         
372         Poly_Triangulation triangulation = BRep_Tool.triangulation(face, Location);
373
374         if(triangulation == null) {
375                 Location.delete();
376                 System.out.println("Encountered empty triangulation after face");
377                 return null;
378         }
379                 
380         boolean reverse = face.orientation()==TopAbs_Orientation.REVERSED;
381
382         int[]triangles = triangulation.triangles();
383         double[]nodes = triangulation.nodes();
384
385         int nofTriangles = triangulation.nbTriangles();
386         int nofNodes = triangulation.nbNodes();
387         
388         triangulation.delete();
389
390         if(nofTriangles < 1) {
391           System.out.println("No triangles for mesh on face");
392           Location.delete();
393           return null;
394         }
395
396         if(nofNodes < 1) {
397             System.out.println("No nodes for mesh on face:");
398             Location.delete();
399             return null;
400         }
401         //System.out.println("v " + nofNodes + " t " +nofTriangles);
402         vtkPolyData partGrid = new vtkPolyData();
403         partGrid.Allocate(nofTriangles, nofTriangles);
404
405         vtkTriangle triangle = new vtkTriangle();
406         vtkIdList list = triangle.GetPointIds();
407         for(int i = 0; i < nofTriangles; i++) 
408         {
409           int n0, n1, n2;
410           if (!reverse) {
411                   n0 = triangles[3 * i]; 
412                   n1 = triangles[3 * i + 1]; 
413                   n2 = triangles[3 * i + 2];
414           } else {
415                   n0 = triangles[3 * i + 2]; 
416                   n1 = triangles[3 * i + 1]; 
417                   n2 = triangles[3 * i];
418           }
419           
420           list.SetId(0, n0);
421           list.SetId(1, n1);
422           list.SetId(2, n2);
423           partGrid.InsertNextCell(triangle.GetCellType(), list);
424           
425         }
426         list.Delete();
427         triangle.Delete();   
428         
429         GP_Trsf transformation = Location.transformation();
430         Location.delete();
431
432         double d_mat[] = new double[16];
433         double d_p[] = new double[3];
434         transformation.getValues(d_mat);
435         Matrix4d mat = new Matrix4d(d_mat);
436         
437         vtkPoints partPoints = new vtkPoints();
438         
439         for(int i = 0; i < nofNodes; i++) {     
440           // FIXME: GP_Trsf.transform(double[]) leaks memory
441                 
442           //double xyz[] = new double[]{nodes[3 * i], nodes[3 * i + 1], nodes[3 * i + 2]};          
443           //transformation.transforms(xyz);
444           //partPoints.InsertPoint(i, xyz);
445                 Point3d p = new Point3d(nodes[3 * i], nodes[3 * i + 1], nodes[3 * i + 2]);
446                 mat.transform(p);
447                 d_p[0] = p.x;
448                 d_p[1] = p.y;
449                 d_p[2] = p.z;
450                 partPoints.InsertPoint(i, d_p);
451         }
452         
453         transformation.delete();
454         
455         partGrid.SetPoints(partPoints);
456         partPoints.Delete();
457        
458         return partGrid;
459     }
460         
461         
462         
463         public static vtkPolyData createPartGrid ( List<Double> meshPoints, List<Integer> meshTriangles)
464     {
465        
466                 
467       
468
469         
470         int nofTriangles = meshTriangles.size() / 3;
471         int nofNodes = meshPoints.size() /3;
472         
473       
474         if(nofTriangles < 1) {
475           System.out.println("No triangles for mesh on face");
476           return null;
477         }
478
479         if(nofNodes < 1) {
480             System.out.println("No nodes for mesh on face:");
481             return null;
482         }
483         //System.out.println("v " + nofNodes + " t " +nofTriangles);
484         vtkPolyData partGrid = new vtkPolyData();
485         partGrid.Allocate(nofTriangles, nofTriangles);
486
487         vtkTriangle triangle = new vtkTriangle();
488         vtkIdList list = triangle.GetPointIds();
489         for(int i = 0; i < nofTriangles; i++) 
490         {
491           int n0, n1, n2;          
492           n0 = meshTriangles.get(3 * i); 
493           n1 = meshTriangles.get(3 * i + 1);
494           n2 = meshTriangles.get(3 * i + 2); 
495
496          
497           list.SetId(0, n0);
498           list.SetId(1, n1);
499           list.SetId(2, n2);
500           partGrid.InsertNextCell(triangle.GetCellType(), list);
501           
502         }
503         list.Delete();
504         triangle.Delete();   
505         
506
507
508         double d_p[] = new double[3];
509
510         
511         vtkPoints partPoints = new vtkPoints();
512         
513         for(int i = 0; i < nofNodes; i++) {     
514
515                 d_p[0] = meshPoints.get(3*i);
516                 d_p[1] = meshPoints.get(3*i+1);
517                 d_p[2] = meshPoints.get(3*i+2);
518                 partPoints.InsertPoint(i, d_p);
519         }
520         
521         partGrid.SetPoints(partPoints);
522         partPoints.Delete();
523        
524         return partGrid;
525     }
526         
527         private static vtkPolyData createTestPartGrid ()
528     {
529                 int size = 64;
530                 
531         double[] nodes = new double[(size+1)*(size+1)*3];
532         int[] triangles = new int[3 * size * size * 2];
533
534         double es = 1.0;
535         for (int i = 0; i <= size; i++) {
536                 for (int j = 0; j <= size; j++) {
537                         int index = j * size + i;
538                         index *= 3;
539                         double x = (double)i * es;
540                         double y = (Math.sin((double)i/(double)size)  + Math.sin((double)j/(double)size)) * es;
541                         double z = (double)j * es;
542                         nodes[index] = x;
543                         nodes[index+1] = y;
544                         nodes[index+2] = z;
545                 }
546         }
547         
548         for (int i = 0; i < size; i++) {
549                 for (int j = 0; j < size; j++) {
550                         int index = j * size + i;
551                         index *= 3;
552                         index *= 2;
553                         triangles[index  ] = (j     * (size+1) + i  );
554                         triangles[index+1] = (j     * (size+1) + i+1);
555                         triangles[index+2] = ((j+1) * (size+1) + i  );
556                         triangles[index+3] = ((j+1) * (size+1) + i  );
557                         triangles[index+4] = ((j  ) * (size+1) + i +1 );
558                         triangles[index+5] = ((j+1) * (size+1) + i +1 );
559                 }
560         }
561
562         int nofTriangles = triangles.length / 3;
563         int nofNodes = nodes.length / 3;
564
565         if(nofTriangles < 1) {
566          
567           return null;
568         }
569
570         if(nofNodes < 1) {
571            
572             return null;
573         }
574         //System.out.println("v " + nofNodes + " t " +nofTriangles);
575         vtkPolyData partGrid = new vtkPolyData();
576         partGrid.Allocate(nofTriangles, nofTriangles);
577
578         vtkTriangle triangle = new vtkTriangle();
579         vtkIdList list = triangle.GetPointIds();
580         for(int i = 0; i < nofTriangles; i++) 
581         {
582           int n0, n1, n2;          
583           n0 = triangles[3 * i]; n1 = triangles[3 * i + 1]; n2 = triangles[3 * i + 2]; // triangles(i).Get(n0, n1, n2);
584
585 //          if(face.orientation() != TopAbs_Orientation.FORWARD) {
586 //              int tmp = n2; n2 = n1; n1 = tmp;
587 //          }
588          
589           list.SetId(0, n0);
590           list.SetId(1, n1);
591           list.SetId(2, n2);
592           partGrid.InsertNextCell(triangle.GetCellType(), list);
593           
594         }
595         list.Delete();
596         triangle.Delete();      
597
598         vtkPoints partPoints = new vtkPoints();
599         for(int i = 0; i < nofNodes; i++) {       
600             double xyz[] = new double[]{nodes[3 * i], nodes[3 * i + 1], nodes[3 * i + 2]};          
601             partPoints.InsertPoint(i, xyz);
602         }
603         
604         partGrid.SetPoints(partPoints);
605         
606         partPoints.Delete();
607
608         return partGrid;
609     }
610         
611         public static void test() {
612                 TopoDS_Shape shape = null;
613                 //shape = OccTriangulator.makeCylinder(new double[]{0,0,0}, new double[]{0,1,0}, 1, 1);
614                 for (int t = 0; t < 5000; t++) {
615                         //shape = OccTriangulator.makeCylinder(new double[]{0,0,0}, new double[]{0,1,0}, 1, 1);
616                         int test = 2;
617                         if (test == 0) {
618                                 vtkAssembly ass = VTKOCCTool.vtkOCCShapeToAssembly(shape);
619                                 vtkPropCollection col;
620                         col = ass.GetParts();
621                         for (int i = 0; i < col.GetNumberOfItems(); i++)
622                         {
623                             vtkProp prop = (vtkProp) col.GetItemAsObject(i);
624                             //System.out.println(prop.Print());
625                             prop.Delete();
626                         }
627                         col.Delete();
628                         ass.Delete();
629                         }
630                         else if (test == 1) {
631                                 //BRepTools.clean(shape);
632                                 
633                                 
634                                 vtkAssembly ass = new vtkAssembly();
635                                 
636                                 double vol = OCCTTool.getBoundingBoxDiagonal(shape);
637                                 double d = 0.001 * vol;
638                                 BRepMesh_IncrementalMesh mesh = new BRepMesh_IncrementalMesh(shape,d);
639                                 TopExp_Explorer expFace = new TopExp_Explorer();
640                                 for (expFace.init(shape, TopAbs_ShapeEnum.FACE); expFace.more(); expFace.next()) {
641                                         TopoDS_Face face = (TopoDS_Face) expFace.current();
642                                         {
643 //                                              TopLoc_Location Location = new TopLoc_Location();
644 //                                              Poly_Triangulation triangulation = BRep_Tool.triangulation(face, Location);
645 //                                              if (triangulation != null) {
646 //                                                      
647 //                                                      int[]triangles = triangulation.triangles();
648 //                                              double[]nodes = triangulation.nodes();
649 //                                              int nofTriangles = triangulation.nbTriangles();
650 //                                              int nofNodes = triangulation.nbNodes();
651 //                                              
652 //                                              triangulation.delete();
653 //                                              
654 //                                              GP_Trsf transformation = Location.transformation();
655 //                                              double d_mat[] = new double[16];
656 //                                              transformation.getValues(d_mat);
657 //                                              Matrix4d mat = new Matrix4d(d_mat);
658 //                                              for(int i = 0; i < nofNodes; i++) {       
659 //                                                  //double xyz[] = new double[]{nodes[3 * i], nodes[3 * i + 1], nodes[3 * i + 2]};          
660 //                                                  Point3d p = new Point3d(nodes[3 * i], nodes[3 * i + 1], nodes[3 * i + 2]);
661 //                                                      //transformation.transforms(xyz);
662 //                                                  mat.transform(p);
663 //                                              }
664 //                                              transformation.delete();
665 //                                              }
666 //                                              
667 //                                              Location.delete();
668                                                 vtkPolyData data = VTKOCCTool.createPartGrid(face);
669                                                 VTKOCCTool.gridToAssembly(ass, data);
670                                                 //data.Delete();
671                                         }
672                                         face.delete();
673                                 }
674                                 expFace.delete();
675                                 mesh.delete();
676                                 
677                                 vtkPropCollection col;
678                         col = ass.GetParts();
679                         for (int i = 0; i < col.GetNumberOfItems(); i++)
680                         {
681                             vtkProp prop = (vtkProp) col.GetItemAsObject(i);
682                             //System.out.println(prop.Print());
683                             prop.Delete();
684                         }
685                         col.Delete();
686                         ass.Delete();
687                         } else if (test == 2) {
688                                 double[] pointStruct = new double[]{0,0,0}, dirStruct = new double[]{0,1,0};
689                                 double radius = 1.0;
690                                 double height = 1.0;
691                                 
692                                 double[] axe = new double[6];
693                                  
694                         System.arraycopy(pointStruct, 0, axe, 0, 3);
695                         System.arraycopy(dirStruct, 0, axe, 3, 3);
696                         org.jcae.opencascade.jni.BRepPrimAPI_MakeCylinder cyl = new org.jcae.opencascade.jni.BRepPrimAPI_MakeCylinder(axe, radius, height, 2 * Math.PI);
697                         org.jcae.opencascade.jni.TopoDS_Shape tds = cyl.shape();
698                         cyl.delete();
699                         
700                         double vol = OCCTTool.getBoundingBoxDiagonal(tds);
701                                 double d = 0.001 * vol;
702                                 BRepMesh_IncrementalMesh mesh = new BRepMesh_IncrementalMesh(tds,d);
703 //                              TopExp_Explorer expFace = new TopExp_Explorer();
704 //                              for (expFace.init(tds, TopAbs_ShapeEnum.FACE); expFace.more(); expFace.next()) {
705 //                                      TopoDS_Face face = (TopoDS_Face) expFace.current();
706 //                                      {
707 //                                              
708 //                                      }
709 //                                      face.delete();
710 //                              }
711                                 mesh.delete();
712                                 
713                         tds.delete();
714                         }
715                         //shape.delete();
716                 System.out.println(t);
717                 }
718                 //shape.delete();
719         }
720 }