]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/shape/vtkMeshObject.java
Remove dependencies on log4j
[simantics/3d.git] / org.simantics.g3d.vtk / src / org / simantics / g3d / vtk / shape / vtkMeshObject.java
1 package org.simantics.g3d.vtk.shape;
2
3 import org.simantics.g3d.shape.Mesh;
4 import org.simantics.g3d.vtk.common.VtkView;
5 import org.simantics.utils.threads.ThreadUtils;
6
7 import vtk.vtkRenderer;
8
9 public class vtkMeshObject {
10         
11         private VtkView panel;
12         private Mesh mesh;
13         
14         private MeshActor meshActor;
15         
16         public vtkMeshObject(VtkView panel, Mesh mesh) {
17                 this.mesh = mesh;
18                 this.panel = panel;
19         }
20         
21         public void visualizeMesh() {
22                 clearActorsVTK();
23                 meshActor = new MeshActor();
24                 meshActor.setMesh(mesh);
25                 //System.out.println("Set mesh " + mesh.getVertices().size() + " " + mesh.getIndices().size() + " " + this);
26                 showActorsVTK();
27         }
28         
29         public MeshActor getActor() {
30                 assert (Thread.currentThread() == panel.getThreadQueue().getThread());
31                 return meshActor;
32         }
33         
34         public void showActorsVTK() {
35                 //System.out.println("showActorsAWT " + this + " " + meshActor != null);
36                 assert (Thread.currentThread() == panel.getThreadQueue().getThread());
37                 panel.lock();
38                 vtkRenderer ren = panel.getRenderer();
39                 if (meshActor != null)
40                         ren.AddActor(meshActor);
41                 panel.unlock();
42         }
43         
44         public void showActors() {
45                 ThreadUtils.asyncExec(panel.getThreadQueue(), new Runnable() {
46                         
47                         @Override
48                         public void run() {
49                                 showActorsVTK();
50                         }
51                 });
52         }
53         
54         public void clearActorsVTK() {
55                 assert (Thread.currentThread() == panel.getThreadQueue().getThread());
56                 
57                 if (meshActor == null)
58                         return;
59                 //System.out.println("clearActorsAwt " + this);
60                 vtkRenderer ren = panel.getRenderer();
61                 if (ren == null)
62                         return;
63                 panel.lock();
64                 if (meshActor.GetVTKId() != 0) {
65                         ren.RemoveActor(meshActor);
66                         meshActor.Delete();
67                 }
68                 panel.unlock();
69                 meshActor = null;
70         }
71         
72         private void clearActorsVTK(MeshActor meshActor) {
73                 assert (Thread.currentThread() == panel.getThreadQueue().getThread());
74                 
75                 if (meshActor == null)
76                         return;
77                 //System.out.println("clearActorsAwt2 " + this);
78                 vtkRenderer ren = panel.getRenderer();
79                 if (ren == null)
80                         return;
81                 panel.lock();
82                 if (meshActor.GetVTKId() != 0) {
83                         ren.RemoveActor(meshActor);
84                         meshActor.Delete();
85                 }
86                 panel.unlock();
87                 meshActor = null;
88         }
89         
90         public void clearActors() {
91                 if (meshActor == null)
92                         return;
93                 ThreadUtils.asyncExec(panel.getThreadQueue(), new Runnable() {
94                         
95                         @Override
96                         public void run() {
97                                 clearActorsVTK(meshActor);
98                         }
99                 });
100         }
101         
102         public void dispose() {
103                 mesh = null;
104                 clearActors();
105         }
106         
107         public void delete() {
108                 mesh = null;
109                 clearActorsVTK();
110         }
111
112 }