[vtkusers] Creating a structured grid of 250x250 cells is causing MS runtime to throw an exception
Bill Lorensen
bill.lorensen at gmail.com
Thu Jul 15 07:56:42 EDT 2010
If you know the number of points in advance, use SetNumberOfPoints()
and SetPoint(), rather than InsertNextPoint().
Insert needs to reallocate memory if the existing array is too small
to handle the next point. It asks for twice the existing size.
There may be other issues, but this is a start.
Bill
On Thu, Jul 15, 2010 at 3:51 AM, Nathan__ <reeves_nathan at hotmail.com> wrote:
>
> I am just trying to create a basic example to ensure that VTK can handle the
> number of cells I need. At 250,000 cells, the MS run time dll is throwing an
> exception due to bad memory allocation. Can anyone please help as to why as
> I am sure this number should easily be handled.
>
> Here is my example:
>
>
> #define DIMENSION_X 500
> #define DIMENSION_Y 500
> #define DIMENSION_Z 1
>
> int main()
> {
> //create points of hexahedron
> vtkPoints *points1 = vtkPoints::New();
> for (int i=0;i<DIMENSION_X;i++)
> {
> for (int j=0;j<DIMENSION_Y;j++)
> {
> for (int k=0;k<DIMENSION_Z;k++)
> {
> points1->InsertNextPoint(i,j,k);
> }
> }
> }
> vtkHexahedron *theHex[DIMENSION_X*DIMENSION_Y*DIMENSION_Z];
> for(int i=0;i<DIMENSION_X*DIMENSION_Y*DIMENSION_Z;i++)
> {
> theHex[i] = vtkHexahedron::New();
> theHex[i]->GetPointIds()->SetNumberOfIds(8); //not needed if use
> insertId
>
> for (int j = 0; j <8; j++)
> {
> theHex[i]->GetPointIds()->SetId(j,j+(i*8)); //this maps internal id 0-7
> to global point Id
> // theHex[i]->GetPointIds()->InsertId(j,j+(i*8));
> }
> }
> vtkStructuredGrid *myStructuredGrid1 = vtkStructuredGrid::New();
> myStructuredGrid1->SetDimensions(DIMENSION_X,DIMENSION_Y,DIMENSION_Z);
> myStructuredGrid1->SetPoints(points1);
>
> //create a mapper for the hexahedron
> vtkDataSetMapper *theHexMapper1;
> theHexMapper1 = vtkDataSetMapper::New();
> theHexMapper1->SetInput(myStructuredGrid1);
>
> //create an actor
> vtkActor * hexActor1;//[NUMBER_OF_SHAPES];
> hexActor1 = vtkActor::New();
> hexActor1->SetMapper(theHexMapper1);
>
> // a renderer and render window
> vtkRenderer *ren1 = vtkRenderer::New();
> vtkRenderWindow *renWin = vtkRenderWindow::New();
> renWin->AddRenderer(ren1);
>
> ren1->AddActor(hexActor1);
>
> // an interactor
> vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
> iren->SetRenderWindow(renWin);
> ren1->SetBackground(1,1,1); // Background color white
>
> // render an image (lights and cameras are created automatically)
> renWin->Render();
>
> iren->Initialize();
> iren->Start();
>
> return 1;
> }
>
>
> Here is my stack trace:
>
> KernelBase.dll!767eb727()
> [Frames below may be incorrect and/or missing, no symbols loaded for
> KernelBase.dll]
> KernelBase.dll!767eb727()
> ntdll.dll!77750e7b()
>> msvcr80d.dll!_unlock(int locknum=8) Line 376 C
> msvcr80d.dll!_unlockexit() Line 760 + 0x7 bytes C
> msvcr80d.dll!_CxxThrowException(void * pExceptionObject=0x3c6cbb50, const
> _s__ThrowInfo * pThrowInfo=0x6c6d3340) Line 161 C++
> msvcr80d.dll!operator new(unsigned int size=128) Line 64 C++
> vtkUtilities.exe!vtkOStrStreamWrapper::vtkOStrStreamWrapper() Line 48 +
> 0x44 bytes C++
> vtkUtilities.exe!vtkDataArrayTemplate<double>::Allocate(int sz=6, int
> __formal=1000) Line 140 + 0x21 bytes C++
> vtkUtilities.exe!vtkDataArrayTemplate<double>::SetNumberOfValues(int
> number=6) Line 849 + 0x18 bytes C++
> vtkUtilities.exe!vtkDataArrayTemplate<double>::SetNumberOfTuples(int
> number=2) Line 406 C++
> vtkUtilities.exe!vtkPoints::SetNumberOfPoints(int number=2) Line 187 +
> 0x19 bytes C++
> vtkUtilities.exe!vtkLine::vtkLine() Line 33 C++
> vtkUtilities.exe!vtkLine::New() Line 26 + 0x73 bytes C++
> vtkUtilities.exe!vtkHexahedron::vtkHexahedron() Line 44 + 0x5 bytes C++
> vtkUtilities.exe!vtkHexahedron::New() Line 28 + 0x73 bytes C++
> vtkUtilities.exe!main() Line 431 + 0x5 bytes C++
> vtkUtilities.exe!__tmainCRTStartup() Line 597 + 0x19 bytes C
> vtkUtilities.exe!mainCRTStartup() Line 414 C
> kernel32.dll!77223677()
> ntdll.dll!77749d42()
> ntdll.dll!77749d15()
>
> --
> View this message in context: http://old.nabble.com/Creating-a-structured-grid-of-250x250-cells-is-causing-MS-runtime-to-throw-an-exception-tp29170212p29170212.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
More information about the vtkusers
mailing list