Can I pre-allocate a vtkCellArray?

I’m already pre-sizing my vtkPoints array with the number of points I know I’ll need. I know how many cells (vtkQuad for my app) I’ll need so is there a way to optimize my vtkCellArray allocation in the same way? I haven’t found an example that does this. They all use InsertNextCell. I see methods for vtkCellArray that suggest they’d do this but I’m not sure what combination to use.

I typically use vtkCellArray::ResizeExact() followed by a Visit() method to populate the cell array. Note that it helps to understand that, under the hood, you are actually populating two arrays: Offsets and Connectivity. Plus you have to understand that the cell array may be either 32 bit or 64 bit storage. It’s a little tricky at first, but the Visit() mechanism simplifies traversal, and the ability to have different cell array types can save a lot of memory.

Aha, The docs for ResizeExact suggested I should use AllocateExact, and I didn’t see what I should use with ResizeExact to actually modify the new cells. I’ve already got a loop through my source data that’s compiling the points and quads, so I’ll need to rethink that to incorporate it into the Visit() functor. (I’m a fan of the visitor pattern so I’m looking forward to it. :wink: )