[Ves] VES polydata object with multiple elements (triangles and lines)
Sebastien HO
sho at traceparts.com
Fri Mar 14 05:49:42 EDT 2014
Thanks for your answer,
Actually, I am using VTK with a C# wrapper and I have tested based on wiki
examples. I cant found VES functions in C# library based on the example you
have sent me. I have tried to build manually a colored cube with edges
using c# wrapper library but I am getting strange results :
- Some face disappeared.
- I do not know how to assign black color to edge. Face colors are
automatically applied to the edge.
Here are screenshots :
Here is my code :
private void ColoredCube()
{
// Create the geometry of the points (the coordinate)
vtkPoints points = vtkPoints.New();
double[,] p = new double[,] {
{10.0, 10.0, 10.0},
{0.0, 10.0, 10.0},
{10.0, 0.0, 10.0},
{0.0, 0.0, 10.0},
{10.0, 0.0, 0.0},
{0.0, 0.0, 0.0},
{10.0, 10.0, 0.0},
{0.0, 10.0, 0.0}
};
// Create topology of the points (a vertex per point)
vtkCellArray vertices = vtkCellArray.New();
int nPts = 8;
int[] ids = new int[nPts];
for (int i = 0; i < nPts; i++)
ids[i] = points.InsertNextPoint(p[i, 0], p[i, 1], p[i,
2]);
int[,] triangles = new int[,]
{
{0, 1, 2},
{2, 1, 3},
{4, 5, 6},
{6, 5, 7},
{3, 5, 2},
{2, 5, 4},
{1, 7, 3},
{3, 7, 5},
{0, 6, 1},
{1, 6, 7},
{2, 4, 0},
{0, 4, 6}
};
int nTrs = 12;
vtkCellArray faces = vtkCellArray.New();
for (int i = 0; i < nTrs; i++)
{
vtkTriangle triangle = vtkTriangle.New();
triangle.GetPointIds().SetId(0, triangles[i, 0]);
triangle.GetPointIds().SetId(1, triangles[i, 1]);
triangle.GetPointIds().SetId(2, triangles[i, 2]);
faces.InsertNextCell(triangle);
}
// Create a cell array to store the triangle in and add the
triangle to it
// Setup two colors - one for each line
byte[] red = new byte[] { 255, 0, 0 };
byte[] green = new byte[] { 0, 255, 0 };
byte[] blue = new byte[] { 0, 0, 255 };
// Setup the colors array
vtkUnsignedCharArray colors = vtkUnsignedCharArray.New();
colors.SetNumberOfComponents(3);
colors.SetName("Colors");
// Add the colors we created to the colors array
colors.InsertNextValue(red[0]);
colors.InsertNextValue(red[1]);
colors.InsertNextValue(red[2]);
colors.InsertNextValue(red[0]);
colors.InsertNextValue(red[1]);
colors.InsertNextValue(red[2]);
colors.InsertNextValue(green[0]);
colors.InsertNextValue(green[1]);
colors.InsertNextValue(green[2]);
colors.InsertNextValue(green[0]);
colors.InsertNextValue(green[1]);
colors.InsertNextValue(green[2]);
colors.InsertNextValue(blue[0]);
colors.InsertNextValue(blue[1]);
colors.InsertNextValue(blue[2]);
colors.InsertNextValue(blue[0]);
colors.InsertNextValue(blue[1]);
colors.InsertNextValue(blue[2]);
colors.InsertNextValue(red[0]);
colors.InsertNextValue(red[1]);
colors.InsertNextValue(red[2]);
colors.InsertNextValue(red[0]);
colors.InsertNextValue(red[1]);
colors.InsertNextValue(red[2]);
colors.InsertNextValue(green[0]);
colors.InsertNextValue(green[1]);
colors.InsertNextValue(green[2]);
colors.InsertNextValue(green[0]);
colors.InsertNextValue(green[1]);
colors.InsertNextValue(green[2]);
colors.InsertNextValue(blue[0]);
colors.InsertNextValue(blue[1]);
colors.InsertNextValue(blue[2]);
colors.InsertNextValue(blue[0]);
colors.InsertNextValue(blue[1]);
colors.InsertNextValue(blue[2]);
//Line creation
int[,] linesArray = new int[,]
{
{0, 1},
{0, 2},
{1, 3},
{3, 2}
};
//Create Lines
int nLs = 4;
vtkCellArray lines = vtkCellArray.New();
for (int i = 0; i < nLs; i++)
{
// Create line
vtkLine line = vtkLine.New();
line.GetPointIds().SetId(0, linesArray[i,0]); //0 is
the index of the Origin in the vtkPoints
line.GetPointIds().SetId(1, linesArray[i, 1]); //1 is
the index of P1 in the vtkPoints
lines.InsertNextCell(line);
}
// Create a polydata to store everything in
vtkPolyData polyData = vtkPolyData.New();
// Add the points to the dataset
polyData.SetPoints(points);
// Add the quad to the dataset
polyData.SetPolys(faces);
polyData.SetLines(lines);
polyData.GetCellData().SetScalars(colors);
// Write the file
vtkXMLPolyDataWriter writer = vtkXMLPolyDataWriter.New();
writer.SetFileName(System.IO.Path.Combine("",
@"C:\Users\sho\Documents\Trace Parts\Projects\cube.vtp"));
writer.SetInput(polyData);
// Optional - set the mode. The default is binary.
//writer.SetDataModeToBinary();
writer.SetDataModeToAscii();
writer.Write();
// Visualize
vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
mapper.SetInput(polyData);
vtkActor actor = vtkActor.New();
actor.SetMapper(mapper);
actor.GetProperty().SetPointSize(20);
vtkRenderWindow renderWindow =
renderWindowControl1.RenderWindow;
vtkRenderer renderer =
renderWindow.GetRenderers().GetFirstRenderer();
renderer.SetBackground(0.3, 0.2, 0.1);
renderer.AddActor(actor);
}
Can you help me correcting my issues.
Regards,
Sébastien.
De : Aashish Chaudhary [mailto:aashish.chaudhary at kitware.com]
Envoyé : vendredi 14 mars 2014 05:40
À : Sebastien HO
Cc : ves at public.kitware.com
Objet : Re: [Ves] VES polydata object with multiple elements (triangles and
lines)
On Thu, Mar 13, 2014 at 5:55 AM, Sebastien HO <sho at traceparts.com> wrote:
Hi folks,
My goal is to create a VES file that contains a geometric representation of
a part with colors and its silhouette (shaded with edges representation).
The silhouette would be computed from our system.
The goal is to have a polydata element with points, colored lines (black)
and colored triangles (depends on face color). I would like to know if VES
file format enables to store this kind of element. If yes, is there any
examples around (like a colored cube with black edges)?
Yes, it is possible. The format for VES geometry data is inspired from
collada format. Its basically is bunch of arrays with metadata on top of it
to describe necessary information
for opengl to extract pieces out of it. You can find an example on how to
draw a plane here:
http://vtk.org/gitweb?p=VES.git;a=blob;f=src/ves/Testing/TestDrawPlane.cpp;h
=fc5db8f7d18c6fc0b256fdd2db117309f582b0ad;hb=HEAD
You should be able to add new primitive (vesPrimitive) using the same
vertices to draw lines as well.
Hope this helps.
- Aashish
Thanks for your help,
Cordialement / Best regards / Mit freundlichen Grüßen / Saludos / Cordiali
saluti
Sébastien HO | R&D Engineer | R&D Department
TraceParts S.A.
Parc Eco Normandie - 76430 St Romain France
sho at traceparts.com <mailto:sho at traceparts.com>
Tel: +33(0)232 <tel:%2B33%280%29232%C2%A0735%C2%A0459> 735 459
Fax: +33(0)232 795 961 <tel:%2B33%280%29232%20795%20961>
<http://www.traceparts.com/> www.traceparts.com
The information contained in this email is intended solely for the
addressee. Access to his email by anyone else is unauthorized. If you are
not the intended recipient, any form of disclosure, reproduction,
distribution or any action taken or refrained form in reliance on it, is
prohibited and may be unlawful. Please notify the sender immediately.
_______________________________________________
Ves mailing list
Ves at public.kitware.com
http://public.kitware.com/cgi-bin/mailman/listinfo/ves
--
| Aashish Chaudhary
| R&D Engineer
| Kitware Inc.
| www.kitware.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/ves/attachments/20140314/94d2611e/attachment-0003.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 11861 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/ves/attachments/20140314/94d2611e/attachment-0003.png>
More information about the Ves
mailing list