[vtk-developers] Creating a vtkPolyData from points and polygons
Mikael Brudfors
mbrudfors at ece.ubc.ca
Wed Apr 9 09:57:15 EDT 2014
Hello,
I hope someone can help me with this very simple issue.
I have a surface stored in two double * as points and polygons (faces) which
I can access using moved_shape_ and get_faces_(). I would like to read this
into a vtkPolyData.
This is how I thought of doing it:
vtkSmartPointer<vtkPoints> points =
vtkSmartPointer<vtkPoints>::New();
for (int i = 0; i < model_->get_moved_shape_rows_(); i+=3)
{
double point[] = {model_->moved_shape_[i],
model_->moved_shape_[i+1], model_->moved_shape_[i+2]};
points->InsertNextPoint(point);
}
vtkSmartPointer<vtkCellArray> polygons =
vtkSmartPointer<vtkCellArray>::New();
for (int i = 0; i < model_->get_faces_rows_(); i+=3)
{
vtkSmartPointer<vtkPolygon> polygon =
vtkSmartPointer<vtkPolygon>::New();
polygon->GetPointIds()->SetNumberOfIds(3);
polygon->GetPointIds()->SetId(model_->get_faces_()[i] - 1.0,
0);
polygon->GetPointIds()->SetId(model_->get_faces_()[i + 1] -
1.0, 1);
polygon->GetPointIds()->SetId(model_->get_faces_()[i + 2] -
1.0, 2);
polygons->InsertNextCell(polygon);
}
vtkSmartPointer<vtkPolyData> polygonPolyData =
vtkSmartPointer<vtkPolyData>::New();
polygonPolyData->SetPoints(points);
polygonPolyData->SetPolys(polygons);
But it crashes at the line, polygons->InsertNextCell(polygon), at the first
iteration of the second for-loop. Seems like a memory allocation issue.
Call stack:
> msvcr100d.dll!_heap_alloc_base(unsigned __int64 size=84) Line
55 C
msvcr100d.dll!_heap_alloc_dbg_impl(unsigned __int64 nSize=32,
int nBlockUse=1, const char * szFileName=0x0000000000000000, int nLine=0,
int * errno_tmp=0x000000000012e910) Line 431 + 0xa bytes C++
msvcr100d.dll!_nh_malloc_dbg_impl(unsigned __int64 nSize=32,
int nhFlag=0, int nBlockUse=1, const char * szFileName=0x0000000000000000,
int nLine=0, int * errno_tmp=0x000000000012e910) Line 239 + 0x22 bytes
C++
msvcr100d.dll!_nh_malloc_dbg(unsigned __int64 nSize=32, int
nhFlag=0, int nBlockUse=1, const char * szFileName=0x0000000000000000, int
nLine=0) Line 302 + 0x2a bytes C++
msvcr100d.dll!_malloc_dbg(unsigned __int64 nSize=32, int
nBlockUse=1, const char * szFileName=0x0000000000000000, int nLine=0) Line
160 + 0x22 bytes C++
msvcr100d.dll!realloc_help(void *
pUserData=0x0000000000000000, unsigned __int64 *
pnNewSize=0x000000000012ea68, int nBlockUse=1, const char *
szFileName=0x0000000000000000, int nLine=0, int fRealloc=1) Line 705 + 0x21
bytes C++
msvcr100d.dll!_realloc_dbg(void *
pUserData=0x0000000000000000, unsigned __int64 nNewSize=32, int nBlockUse=1,
const char * szFileName=0x0000000000000000, int nLine=0) Line 1040 + 0x29
bytes C++
msvcr100d.dll!realloc(void * pUserData=0x0000000000000000,
unsigned __int64 nNewSize=32) Line 60 + 0x20 bytes C++
vtkCommon.dll!vtkDataArrayTemplate<__int64>::ResizeAndExtend(__int64 sz=4)
Line 355 + 0x1e bytes C++
vtkCommon.dll!vtkDataArrayTemplate<__int64>::WritePointer(__int64 id=0,
__int64 number=4) Line 865 + 0xf bytes C++
vtkCommon.dll!vtkIdTypeArray::WritePointer(__int64 id=0,
__int64 number=4) Line 129 + 0x3c bytes C++
vtkFiltering.dll!vtkCellArray::InsertNextCell(__int64 npts=3,
const __int64 * pts=0x00000000030c2420) Line 249 + 0x1f bytes
C++
vtkFiltering.dll!vtkCellArray::InsertNextCell(vtkCell *
cell=0x00000000030e2cc0) Line 294 C++
Any help would be greatly appreciated!
Thank you,
Mikael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtk-developers/attachments/20140409/5a4511b2/attachment.html>
More information about the vtk-developers
mailing list