MCPcopy Create free account
hub / github.com/Kitware/VTK / Crop

Method Crop

Common/DataModel/vtkImageData.cxx:1171–1313  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

1169
1170//------------------------------------------------------------------------------
1171void vtkImageData::Crop(const int* updateExtent)
1172{
1173 const int* extent = this->GetExtent();
1174
1175 // Do nothing for empty datasets:
1176 for (int dim = 0; dim < 3; ++dim)
1177 {
1178 if (extent[2 * dim] > extent[2 * dim + 1])
1179 {
1180 vtkDebugMacro(<< "Refusing to crop empty dataset.");
1181 return;
1182 }
1183 }
1184
1185 int nExt[6];
1186 int idxX, idxY, idxZ;
1187 int maxX, maxY, maxZ;
1188 vtkIdType outId, inId, inIdY, inIdZ, incZ, incY;
1189 vtkImageData* newImage;
1190 vtkIdType numPts, numCells, tmp;
1191
1192 // If extents already match, then we need to do nothing.
1193 if (extent[0] == updateExtent[0] && extent[1] == updateExtent[1] &&
1194 extent[2] == updateExtent[2] && extent[3] == updateExtent[3] && extent[4] == updateExtent[4] &&
1195 extent[5] == updateExtent[5])
1196 {
1197 return;
1198 }
1199
1200 // Take the intersection of the two extent so that
1201 // we are not asking for more than the extent.
1202 memcpy(nExt, updateExtent, 6 * sizeof(int));
1203 nExt[0] = std::max(nExt[0], extent[0]);
1204 nExt[1] = std::min(nExt[1], extent[1]);
1205 nExt[2] = std::max(nExt[2], extent[2]);
1206 nExt[3] = std::min(nExt[3], extent[3]);
1207 nExt[4] = std::max(nExt[4], extent[4]);
1208 nExt[5] = std::min(nExt[5], extent[5]);
1209
1210 // If the extents are the same just return.
1211 if (extent[0] == nExt[0] && extent[1] == nExt[1] && extent[2] == nExt[2] &&
1212 extent[3] == nExt[3] && extent[4] == nExt[4] && extent[5] == nExt[5])
1213 {
1214 vtkDebugMacro("Extents already match.");
1215 return;
1216 }
1217
1218 // How many point/cells.
1219 numPts = (nExt[1] - nExt[0] + 1) * (nExt[3] - nExt[2] + 1) * (nExt[5] - nExt[4] + 1);
1220 // Conditional are to handle 3d, 2d, and even 1d images.
1221 tmp = nExt[1] - nExt[0];
1222 if (tmp <= 0)
1223 {
1224 tmp = 1;
1225 }
1226 numCells = tmp;
1227 tmp = nExt[3] - nExt[2];
1228 if (tmp <= 0)

Callers 7

executeFunction · 0.45
RequestDataMethod · 0.45
RequestDataMethod · 0.45
RequestDataMethod · 0.45
RootExecuteMethod · 0.45
RequestDataMethod · 0.45

Calls 11

DeleteMethod · 0.65
maxFunction · 0.50
minFunction · 0.50
NewFunction · 0.50
GetExtentMethod · 0.45
SetExtentMethod · 0.45
GetPointDataMethod · 0.45
GetCellDataMethod · 0.45
CopyAllocateMethod · 0.45
CopyDataMethod · 0.45
ShallowCopyMethod · 0.45

Tested by 1

executeFunction · 0.36