polyData.Allocate(mesh.getIndices().size()/3, mesh.getIndices().size()/3);
vtkTriangle triangle = new vtkTriangle();
- vtkIdList list = triangle.GetPointIds();
- for (int i = 0; i < mesh.getIndices().size(); i+=3) {
- list.SetId(0, mesh.getIndices().get(i));
- list.SetId(1, mesh.getIndices().get(i+1));
- list.SetId(2, mesh.getIndices().get(i+2));
- polyData.InsertNextCell(triangle.GetCellType(), list);
- }
- list.Delete();
- triangle.Delete();
-
-
- vtkPoints points = new vtkPoints();
- for (int i = 0; i < mesh.getVertices().size(); i++) {
- Tuple3d p = mesh.getVertices().get(i);
- points.InsertPoint(i, p.x, p.y, p.z);
- }
-
- polyData.SetPoints(points);
- points.Delete();
-
- if (mesh.getNormals() != null) {
- vtkFloatArray normals = new vtkFloatArray();
- normals.SetNumberOfComponents(3);
- normals.SetNumberOfTuples(mesh.getNormals().size());
- for (int i = 0; i < mesh.getNormals().size(); i++) {
- Tuple3d p = mesh.getNormals().get(i);
- normals.InsertTuple3(i, p.x, p.y, p.z);
- }
- vtkPointData pointData = polyData.GetPointData();
- pointData.SetNormals(normals);
- normals.Delete();
- pointData.Delete();
- }
- if (mesh.getColors() != null) {
- vtkUnsignedCharArray colors = new vtkUnsignedCharArray();
- colors.SetName("Colors");
- colors.SetNumberOfComponents(3);
- colors.SetNumberOfTuples(mesh.getColors().size());
- for (int i = 0; i < mesh.getColors().size(); i++) {
- Color4d c = mesh.getColors().get(i);
- colors.InsertTuple3(i, 255.0* c.x, 255.0 * c.y, 255.0 * c.z);
- }
- polyData.GetPointData().AddArray(colors);
- colors.Delete();
-
- }
- return polyData;
+ vtkIdList list = triangle.GetPointIds();
+ for (int i = 0; i < mesh.getIndices().size(); i+=3) {
+ list.SetId(0, mesh.getIndices().get(i));
+ list.SetId(1, mesh.getIndices().get(i+1));
+ list.SetId(2, mesh.getIndices().get(i+2));
+ polyData.InsertNextCell(triangle.GetCellType(), list);
+ }
+ list.Delete();
+ triangle.Delete();
+
+
+ vtkPoints points = new vtkPoints();
+ for (int i = 0; i < mesh.getVertices().size(); i++) {
+ Tuple3d p = mesh.getVertices().get(i);
+ points.InsertPoint(i, p.x, p.y, p.z);
+ }
+
+ polyData.SetPoints(points);
+ points.Delete();
+
+ if (mesh.getNormals() != null) {
+ vtkFloatArray normals = new vtkFloatArray();
+ normals.SetNumberOfComponents(3);
+ normals.SetNumberOfTuples(mesh.getNormals().size());
+ for (int i = 0; i < mesh.getNormals().size(); i++) {
+ Tuple3d p = mesh.getNormals().get(i);
+ normals.InsertTuple3(i, p.x, p.y, p.z);
+ }
+ vtkPointData pointData = polyData.GetPointData();
+ pointData.SetNormals(normals);
+ normals.Delete();
+ pointData.Delete();
+ }
+ if (mesh.getColors() != null) {
+ vtkUnsignedCharArray colors = new vtkUnsignedCharArray();
+ colors.SetName("Colors");
+ colors.SetNumberOfComponents(3);
+ colors.SetNumberOfTuples(mesh.getColors().size());
+ for (int i = 0; i < mesh.getColors().size(); i++) {
+ Color4d c = mesh.getColors().get(i);
+ colors.InsertTuple3(i, 255.0* c.x, 255.0 * c.y, 255.0 * c.z);
+ }
+ polyData.GetPointData().AddArray(colors);
+ colors.Delete();
+
+ }
+ return polyData;
}
public void setMesh(Mesh mesh) {
vtkPolyDataMapper mapper = new vtkPolyDataMapper();
vtkPolyData polyData = createPolyData(mesh);
-
- if (mesh.getNormals() == null) {
- vtkPolyDataNormals normals = new vtkPolyDataNormals();
- normals.SetInputData(polyData);
- normals.ComputePointNormalsOn();
- mapper.SetInputConnection(normals.GetOutputPort());
- normals.GetOutputPort().Delete();
- normals.Delete();
- } else {
- mapper.SetInputData(polyData);
- }
-
- if (mesh.getColors() != null) {
- mapper.ScalarVisibilityOn();
- mapper.SetScalarModeToUsePointFieldData();
- mapper.SelectColorArray("Colors");
- }
-
- SetMapper(mapper);
- mapper.Delete();
- polyData.GetPointData().Delete();
- polyData.Delete();
-
+
+ if (mesh.getNormals() == null) {
+ vtkPolyDataNormals normals = new vtkPolyDataNormals();
+ normals.SetInputData(polyData);
+ normals.ComputePointNormalsOn();
+ mapper.SetInputConnection(normals.GetOutputPort());
+ normals.GetOutputPort().Delete();
+ normals.Delete();
+ } else {
+ mapper.SetInputData(polyData);
+ }
+
+ if (mesh.getColors() != null) {
+ mapper.ScalarVisibilityOn();
+ mapper.SetScalarModeToUsePointFieldData();
+ mapper.SelectColorArray("Colors");
+ }
+
+ SetMapper(mapper);
+ mapper.Delete();
+ polyData.GetPointData().Delete();
+ polyData.Delete();
+
}
@Override