Ok! So, I have managed to use my underlying C arrays without much overhead. <br>Here, is the code:<br><br> float *vtkPts = (float * ) argv[0];<br> int *vtkCells = (int * ) argv[1];<br> int PtsArraySize = * (int *) argv[2];<br>
int CellArraySize = * (int *) argv[3]; <br> int nCells = * (int *) argv[4];<br><br> // Here comes the vtk stuff<br><br> vtkSmartPointer <vtkFloatArray> pts_fltarr = vtkSmartPointer<vtkFloatArray>::New();<br>
pts_fltarr->SetNumberOfComponents(3); // X,Y,Z<br> pts_fltarr->SetArray(vtkPts, PtsArraySize, 1);<br><br> vtkSmartPointer <vtkPoints> Points = vtkSmartPointer<vtkPoints>::New();<br> Points->SetData(pts_fltarr);<br>
<br> <br> vtkSmartPointer <vtkIdTypeArray> Conn = vtkSmartPointer<vtkIdTypeArray>::New();<br> Conn->SetArray(vtkCells, CellArraySize,1);<br><br> vtkSmartPointer <vtkCellArray> Polys = vtkSmartPointer<vtkCellArray>::New();<br>
Polys->SetCells(nCells,Conn);<br><br> vtkSmartPointer <vtkPolyData> Tracts = vtkSmartPointer <vtkPolyData>::New();<br><br> Tracts->SetPoints(Points);<br> Tracts->SetLines(Polys);<br> Tracts->Update();<br>
<br> vtkSmartPointer <vtkTubeFilter> Tubes = vtkSmartPointer<vtkTubeFilter>::New();<br> Tubes->SetInput(Tracts);<br> Tubes->SetRadius(.2);<br> Tubes->SetNumberOfSides(6);<br> Tubes->Update();<br>
<br>------------------------------<br><br>Now, I want to pass back two new arrays to IDL that contains the point data and the triangle strip (connectivity). <br>Again, if I could just access the arrays directly life would be much simpler. However, it appears going in reverse might be harder than what I have already setup.<br>
<br>This will give me the size needed for the arrays:<br><br> // pts<br> int NumPoints = Tubes->GetOutput()->GetNumberOfPoints();<br><br> // cells/strips/num of elemens in array<br> int NumConn = Tubes->GetOutput()->GetStrips()->GetSize();<br>
<br>The plan would be to allocate an array of ints (vtkIdType) to hold the strips and an array of floats to hold the point data. Both, 1D.<br><br>Strips (connectivity):<br>-------------------------------<br><br>Tubes->GetOutput()->GetStrips()->GetData() // Will give me a vtkIdTypeArray - but I really want is an array of vtkIdType.<br>
-- At this point, I'd like to use a getArray function like the setArray function - but, it doesn't exist.<br> -- So, do I need to loop through the whole vtkIdTypeArray and copy it into an array of vtkIdType??<br>
-- or can I avoid this with some trick that I can't figure out?<br><br>Points:<br>----------<br>Tubes->GetOutput()->GetPoints() // will give me a vtkPoints object with all of my points<br><br>-- Again, at this point, I'd like to be able to extract the float array in the same way I set it, i.e setdata()<br>
-- I don't see a good option to do this.<br>-- Do, I need to go point-by-point filling a new float array?<br><br><br>Let me know if you can think of a way I can accomplish this? I can write my own code to it. But, wonder if there is a way to do this and my lack of experience with vtk is not allowing me to see it.<br>
<br>Thanks again,<br><br>Matt<br><br><br><br><br><div class="gmail_quote">On Fri, Jan 15, 2010 at 4:38 PM, Matt <span dir="ltr"><<a href="mailto:pspmatt@gmail.com">pspmatt@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Yup, I figured that out as soon as I sent the email.<br><br>Thanks for all the help!<br><font color="#888888"><br>Matt</font><div><div></div><div class="h5"><br><br><div class="gmail_quote">On Fri, Jan 15, 2010 at 3:33 PM, David Gobbi <span dir="ltr"><<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi Matt,<br>
<br>
If your vtk is built with VTK_USE_64BIT_IDS=OFF, then vtkIdType is<br>
just a typedef for "int" and vtkIdType will be interchangeable with<br>
int. If vtkIdType is a 64-bit int (or if you want your code to work<br>
when vtkIdType is 64-bit) then yes, you will have to copy your int<br>
data into the vtkIdTypeArray.<br>
<font color="#888888"><br>
David<br>
</font><div><div></div><div><br>
<br>
On Fri, Jan 15, 2010 at 2:03 PM, Matt <<a href="mailto:pspmatt@gmail.com" target="_blank">pspmatt@gmail.com</a>> wrote:<br>
> Thanks so much! That was really helpful.<br>
> I am able to access my C array directly for vtkPoints. That is awesome.<br>
> You explanation and advice really helped my understanding.<br>
><br>
> I am now trying to figure out this vtkCellArray which I understand takes a<br>
> vtkIdTypeArray which contains vtkIdType.<br>
> Again, I would like to be able to access my c array directly (if possible).<br>
> Or, use the least overhead possible.<br>
> My c array is of type int and takes the form: N, p1, p2, p3, N, p2, p3,<br>
> p4, p5, N, .... The number of points per cell varies.<br>
> I guess I can't access this c array directly because it is not the right<br>
> type. Seems a shame. The data seems to be represented exactly as the<br>
> vtkCellArray is organized or at least in my limited understanding it does.<br>
><br>
> So, what's the best plan of action? Fill an array of vtkIdType with the<br>
> contents of my int c array. And, then pass that into a vtkIdTypeArray, which<br>
> I then pass onto the vtkCellArray.<br>
><br>
> Any advice, code snippets would be much appreciated. I am a bit stuck.<br>
><br>
> Matt<br>
><br>
><br>
><br>
> On Fri, Jan 15, 2010 at 11:03 AM, David Gobbi <<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>> wrote:<br>
>><br>
>> The vtkPoints() class has a SetData() method as you have already seen,<br>
>> and the vtkCellArray class has a method called SetCells(int ncells,<br>
>> vtkIdTypeArray *cells) that takes a vtkDataArray that contains the<br>
>> connectivity array.<br>
>><br>
>> For vtkPoints::SetData(), the vtkDataArray must be either a<br>
>> vtkFloatArray or a vtkDoubleArray. For vtkCellArray::SetCells(), only<br>
>> a vtkIdTypeArray containing "vtkIdType" values is allowed... vtkIdType<br>
>> is a typedef for either "int" or "long long" depending on whether<br>
>> VTK_USE_64BIT_IDS was set by cmake.<br>
>><br>
>> You can efficiently set up a vtkDataArray by using the SetTuple()<br>
>> method, since it is an inline method. In fact, so is the<br>
>> vtkPoints::SetPoint() method.<br>
>><br>
>> If you have a huge data set and don't want to copy your data, you can<br>
>> have VTK use your C arrays directly. The VTK arrays have a method<br>
>> called "SetArray()" that can be used like this:<br>
>><br>
>> vtkFloatArray *array = vtkFloatArray::New();<br>
>> array->SetNumberOfComponents(3);<br>
>> array->SetArray(c_array, number_of_points*3, 1);<br>
>><br>
>> The "1" on the end tells VTK not call "delete []" or "free()" on<br>
>> c_array when the vtkDataArray is freed. You don't have to call<br>
>> SetNumberOfTuples() because VTK will automatically set the size of the<br>
>> array from the size of the c_array you give it.<br>
>><br>
>> Note that VTK always uses vtkIdType for its cells, you can't choose<br>
>> whether to use 32-bit or 64-bit ids at run time.<br>
>><br>
>> David<br>
>><br>
>><br>
>> On Fri, Jan 15, 2010 at 9:21 AM, Matt <<a href="mailto:pspmatt@gmail.com" target="_blank">pspmatt@gmail.com</a>> wrote:<br>
>> > Hello,<br>
>> ><br>
>> > I have recently started using VTK. First, let me say thanks! It is<br>
>> > amazing.<br>
>> > I am working on an application in ITTVIS IDL that will communicate with<br>
>> > a<br>
>> > DLL (C++) that contains VTK code.<br>
>> > I have the DLL and the communication working fine and am able to pass<br>
>> > data<br>
>> > between the programs.<br>
>> > I want to make a bunch of polygons and pass them through the generate<br>
>> > tube<br>
>> > filter before passing it back to IDL.<br>
>> ><br>
>> > I am passing two arrays from IDL:<br>
>> ><br>
>> > 1) Array of points in floats. 1D. Form: X0 Y0 Z0 X1 Y1 Z1 X2 Y2 Z2<br>
>> ><br>
>> > 2) Array of connectivity in int. 1D Form: N P0 P1 P2 N P1 P3 N<br>
>> > P2<br>
>> > P3<br>
>> ><br>
>> ><br>
>> > ** I think the data is in the form that it is represented in memory in<br>
>> > VTK.<br>
>> > (As in pg. 126 4th edition, OO approach to 3D graphics)<br>
>> ><br>
>> > The usual approach would be to create a vtkPolyData array (for the<br>
>> > polygons), vtkPoints, and a vtkCellArray for connectivity).<br>
>> > And, then to fill them using vtkPoints->InsertPoint,<br>
>> > vtkCellArray->InsertNextCell, and then vtkPolyData->setPoints.<br>
>> ><br>
>> > However, I need this to be very effcient as I may be calling these<br>
>> > routines<br>
>> > repeatedly. Given, that the data is almost in the form that VTK<br>
>> > expects.<br>
>> > I want to be able to stuff the data in whole vs point by point, cell by<br>
>> > cell.<br>
>> ><br>
>> > I can't seem to find a good explanation on how I would go about doing<br>
>> > this.<br>
>> ><br>
>> > There seems to be a ->setData method in vtkPoints class but it takes a<br>
>> > vtkDataArray and I currently just have a plain old array of floats.<br>
>> > I think the same goes for setCells in the vtkCellArray class.<br>
>> ><br>
>> > Could someone give me a quick example of the few lines of code it would<br>
>> > take<br>
>> > to impelement this. Or,, point me to a resource that shows an example<br>
>> > of<br>
>> > this<br>
>> ><br>
>> > Thanks<br>
>> ><br>
>> > Matt<br>
>> ><br>
>> > _______________________________________________<br>
>> > Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
>> ><br>
>> > Visit other Kitware open-source projects at<br>
>> > <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
>> ><br>
>> > Please keep messages on-topic and check the VTK FAQ at:<br>
>> > <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
>> ><br>
>> > Follow this link to subscribe/unsubscribe:<br>
>> > <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
>> ><br>
>> ><br>
><br>
><br>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br>