vtkDataSet * avtLineoutFilter::Sampling(vtkDataSet *in_ds, int domain) { vtkDataSetRemoveGhostCells *ghosts = vtkDataSetRemoveGhostCells::New(); ghosts->SetInput(in_ds); ghosts->Update(); vtkLineoutFilter *filter = vtkLineoutFilter::New(); filter->SetInput(ghosts->GetOutput()); filter->SetPoint1(point1); filter->SetPoint2(point2); filter->SetNumberOfSamplePoints(numberOfSamplePoints); filter->GetOutput()->SetUpdateGhostLevel(0); vtkPolyData *outPolys = filter->GetOutput(); outPolys->Update(); vtkDataSet *rv = outPolys; if (outPolys->GetNumberOfCells() == 0 || outPolys->GetNumberOfPoints() == 0) { debug5 << "vtkLineoutFilter returned empty DS for domain " << domain << "." << endl; rv = NULL; } ManageMemory(rv); filter->Delete(); ghosts->Delete(); return rv; }
void avtDataTreeIterator::ReleaseData(void) { avtSIMODataTreeIterator::ReleaseData(); ManageMemory(NULL); // Cleans out any stored datasets. }
vtkDataSet * avtCartographicProjectionFilter::ExecuteData(vtkDataSet *in_ds, int, std::string) { /* The projection mappings in VTK, based on the libproj4 library, expect data with coordinates * in the range [-180, 180] for longitude, and [-90, 90] for latitude. * Further, mapped grids cannot sit on Rectilinear Grids. So, we start by converting rectilinear grids * to structured grids (i.e. fully curvilinear) * A new grid is created based on the input, coordinates are projected, then remapped to the classic range * of [-180, 180] for longitude, and [-90, 90] for latitude */ int do_type = in_ds->GetDataObjectType(); int dims[3], numPts = in_ds->GetNumberOfPoints(); vtkPointSet *ds; vtkCellArray *ca; double in_bounds[6], out_bounds[6], tol = 10., p_pt[3], c_pt[3]; vtkPoints *inPts = vtkVisItUtility::NewPoints(in_ds); inPts->Allocate(numPts); inPts->SetNumberOfPoints(numPts); for(int i=0; i < numPts; i++) { in_ds->GetPoint(i, c_pt); // the next two lines used for our Geo-physics grid //c_pt[0] = (c_pt[2] - M_PI)*179.999/M_PI; //c_pt[1] = (c_pt[1] - M_PI_2)*89.999/M_PI_2; // this is used for our Geo-physics grid c_pt[2] = 0.0; inPts->SetPoint(i, c_pt); } inPts->GetBounds(in_bounds); debug4 << "Input Bounds[6] = " << in_bounds[0] << " " << in_bounds[1] << " " << in_bounds[2] << " " << in_bounds[3] << " " << in_bounds[4] << " " << in_bounds[5] << endl; vtkGeoProjection *proj = vtkGeoProjection::New(); proj->SetCentralMeridian(atts.GetCentralMeridian()); debug4 << "Central Meridian = " << proj->GetCentralMeridian() << endl; vtkGeoTransform *geoXform = vtkGeoTransform::New(); // Here we could have as many of the 100+ projections available. // I'm not sure people want to see a pull-down list with 100+ items proj->SetName(atts.ProjectionID_ToString(atts.GetProjectionID()).c_str()); debug4 << "setting name of projection " << atts.ProjectionID_ToString(atts.GetProjectionID()) << endl; geoXform->SetDestinationProjection(proj); vtkPoints *newPoints = vtkPoints::New(inPts->GetDataType()); geoXform->TransformPoints(inPts, newPoints); newPoints->GetBounds(out_bounds); debug4 << "Output Bounds[6] = " << out_bounds[0] << " " << out_bounds[1] << " " << out_bounds[2] << " " << out_bounds[3] << " " << out_bounds[4] << " " << out_bounds[5] << endl; // rescale coordinates to the original set of longitude and latitude ranges. // this is motivated by the fact that the continents shapefile provided by Brad for the SC'12 tutorial // does not range fully to the North Pole. It was wrong to stretch its projection to +90 degrees. double alpha; for(int i=0; i < numPts; i++) { newPoints->GetPoint(i, c_pt); alpha = (c_pt[0] - out_bounds[0]) / (out_bounds[1]-out_bounds[0]); c_pt[0] = alpha * in_bounds[1] + (1.0 - alpha) * in_bounds[0]; alpha = (c_pt[1] - out_bounds[2]) / (out_bounds[3]-out_bounds[2]); c_pt[1] = alpha * in_bounds[3] + (1.0 - alpha) * in_bounds[2]; // only touch the X and Y coordinates. Ignore Z newPoints->SetPoint(i, c_pt); } // mark the coordinates as Modified to force a call to vtkPoints::ComputeBounds() // otherwise a ResetView() has trouble resetting. newPoints->Modified(); newPoints->GetBounds(out_bounds); debug4 << "Output Bounds[6] = " << out_bounds[0] << " " << out_bounds[1] << " " << out_bounds[2] << " " << out_bounds[3] << " " << out_bounds[4] << " " << out_bounds[5] << endl; vtkCellArray *ca_n; int changeOfSigns = 0, k; switch(do_type) { case VTK_STRUCTURED_GRID: ds = vtkStructuredGrid::New(); static_cast<vtkStructuredGrid *>(in_ds)->GetDimensions(dims); // make sure 3rd dimension is set in case we were given 2D datasets (e.g pressure.cdf) dims[2] = 1; static_cast<vtkStructuredGrid *>(ds)->SetDimensions(dims); ds->ShallowCopy(in_ds); break; case VTK_RECTILINEAR_GRID: ds = vtkStructuredGrid::New(); static_cast<vtkRectilinearGrid *>(in_ds)->GetDimensions(dims); // make sure 3rd dimension is set in case we were given 2D datasets (e.g pressure.cdf) dims[2] = 1; static_cast<vtkStructuredGrid *>(ds)->SetDimensions(dims); ds->ShallowCopy(in_ds); break; case VTK_POLY_DATA: // some special treatment is done here for polylines which - when projected - // "fall on the other side of the Earth". // Detect an line segment within the polyline which has a very long length and split. ds = vtkPolyData::New(); ca_n = vtkCellArray::New(); static_cast<vtkPolyData *>(ds)->SetPolys(ca_n); ca_n->Delete(); ca = static_cast<vtkPolyData *>(in_ds)->GetPolys(); vtkIdType npts, *pts; ca->InitTraversal(); // for each polygon, change for big changes in coordinates and split lines for(int i =0; i < ca->GetNumberOfCells (); i++) { changeOfSigns = 0; ca->GetNextCell(npts, pts); k = npts-1; // start from end and split if necessary for(int j =npts-1; j >0; j--) { newPoints->GetPoint(pts[j-1], p_pt); // previous pt newPoints->GetPoint(pts[j], c_pt); // current pt // if(((p_pt[0] > 0) && (c_pt[0] < 0) || (p_pt[0] < 0) && (c_pt[0] > 0))) // compute a 2d distance if(sqrt((p_pt[0] - c_pt[0])*(p_pt[0] - c_pt[0]) + (p_pt[1] - c_pt[1])*(p_pt[1] - c_pt[1])) > tol ) { changeOfSigns++; ca_n->InsertNextCell(k-j+1, &pts[j]); k = j-1; } // cerr << "pts["<< pts[j] << "] = " << x[0] << " " << x[1] << " " << x[2] << endl; } if(changeOfSigns == 0) { ca_n->InsertNextCell(npts, pts); } // full polygon (original) else { ca_n->InsertNextCell(k+1, pts); // what is left-over after all the splits } } break; default: debug4 << "not supported for this grid type" <<endl; return in_ds; } ds->SetPoints(newPoints); if(do_type != VTK_POLY_DATA) debug4 << "dims = " << dims[0] << " x " << dims[1] << " x " << dims[2] << endl; if(do_type == VTK_RECTILINEAR_GRID) inPts->Delete(); ManageMemory(ds); ds->Delete(); newPoints->Delete(); proj->Delete(); geoXform->Delete(); return ds; }
vtkDataSet * avtDualMeshFilter::ExecuteData(vtkDataSet *in_ds, int, std::string) { // require Rectilinear Grid int mesh_type = in_ds->GetDataObjectType(); if (mesh_type != VTK_RECTILINEAR_GRID) { EXCEPTION1(ImproperUseException, "The Dual Mesh operator only works on rectilinear grids."); } vtkRectilinearGrid *rgrid = (vtkRectilinearGrid *) in_ds; vtkRectilinearGrid *result = vtkRectilinearGrid::New(); // shallow copy the field data result->GetFieldData()->ShallowCopy(rgrid->GetFieldData()); int dims[3] = {0,0,0}; int rdims[3] = {1,1,1}; rgrid->GetDimensions(dims); // see if we are expanding or contracting bool expand = actualMode != DualMeshAttributes::ZonesToNodes; vtkDataArray *x_coords = rgrid->GetXCoordinates(); vtkDataArray *y_coords = rgrid->GetYCoordinates(); vtkDataArray *z_coords = rgrid->GetZCoordinates(); vtkDataArray *res_x_coords = NULL; vtkDataArray *res_y_coords = NULL; vtkDataArray *res_z_coords = NULL; if(expand) res_x_coords = ExpandDual(x_coords); else res_x_coords = ContractDual(x_coords); rdims[0] = res_x_coords->GetNumberOfTuples(); if( dims[1] > 1 ) // 2d & 3d { if(expand) res_y_coords = ExpandDual(y_coords); else res_y_coords = ContractDual(y_coords); rdims[1] = res_y_coords->GetNumberOfTuples(); } if( dims[2] > 1 ) // 3d { if(expand) res_z_coords = ExpandDual(z_coords); else res_z_coords = ContractDual(z_coords); rdims[2] = res_z_coords->GetNumberOfTuples(); } result->SetDimensions(rdims); result->SetXCoordinates(res_x_coords); if(dims[1]>1) result->SetYCoordinates(res_y_coords); else result->SetYCoordinates(rgrid->GetYCoordinates()); if(dims[2]>1) result->SetZCoordinates(res_z_coords); else result->SetZCoordinates(rgrid->GetZCoordinates()); if(res_x_coords) res_x_coords->Delete(); if(res_y_coords) res_y_coords->Delete(); if(res_z_coords) res_z_coords->Delete(); if(expand) { // change point data to cell data result->GetCellData()->ShallowCopy(rgrid->GetPointData()); } else { // change cell data to point data result->GetPointData()->ShallowCopy(rgrid->GetCellData()); } ManageMemory(result); result->Delete(); return result; }
vtkDataSet * avtPointToGlyphFilter::ExecuteData(vtkDataSet *in_ds, int, std::string) { if (in_ds == NULL || in_ds->GetNumberOfCells() <= 0) { return NULL; } if (GetInput()->GetInfo().GetAttributes().GetTopologicalDimension() != 0) { return in_ds; } vtkPolyData *glyph = NULL; if (GetInput()->GetInfo().GetAttributes().GetSpatialDimension() == 2) { glyph = glyph2D; } else { glyph = glyph3D; } // // The glyph filter will glyph every input point, regardless of whether or // not it is being used. If we have poly data or an unstructured grid, // we likely have unused points. // vtkPolyDataRelevantPointsFilter *pdrp = vtkPolyDataRelevantPointsFilter::New(); vtkUnstructuredGridRelevantPointsFilter *ugrp = vtkUnstructuredGridRelevantPointsFilter::New(); vtkDataSet *ds = in_ds; int dstype = ds->GetDataObjectType(); if (dstype == VTK_POLY_DATA) { pdrp->SetInput((vtkPolyData *) ds); ds = pdrp->GetOutput(); } else if (dstype == VTK_UNSTRUCTURED_GRID) { ugrp->SetInput((vtkUnstructuredGrid *) ds); ds = ugrp->GetOutput(); } // // If there is no glypher, then just copy the points into vtkPolyData // if (glyphType == 3) { // vtkGeometryFilter should work just fine for this. vtkGeometryFilter *geom = vtkGeometryFilter::New(); geom->SetInput(ds); vtkPolyData *output = geom->GetOutput(); geom->Update(); ManageMemory(output); pdrp->Delete(); ugrp->Delete(); geom->Delete(); return output; } // // Now construct the glypher. // vtkGlyph3D *glyphFilter = vtkGlyph3D::New(); if (!scaleByVarEnabled) { glyphFilter->SetScaleModeToDataScalingOff(); } else { glyphFilter->SetScaleModeToScaleByScalar(); } glyphFilter->SetScaleFactor(pointSize); glyphFilter->SetVectorModeToVectorRotationOff(); glyphFilter->SetIndexModeToOff(); glyphFilter->SetSource(glyph); glyphFilter->SetInput(ds); glyphFilter->SetGeneratePointIds(1); glyphFilter->Update(); vtkDataSet *output = glyphFilter->GetOutput(); // // The VTK glyphing routine does not copy point data. Copy that over // manually. // vtkIdTypeArray *ids = (vtkIdTypeArray *) output->GetPointData()->GetArray("InputPointIds"); ids->Register(NULL); vtkPointData *out_pd = vtkPointData::New(); vtkPointData *in_pd = ds->GetPointData(); int npts = output->GetNumberOfPoints(); out_pd->CopyAllocate(in_pd, npts); int i; for (i = 0 ; i < npts ; i++) { out_pd->CopyData(in_pd, ids->GetValue(i), i); } for (i = 0 ; i < out_pd->GetNumberOfArrays() ; i++) { vtkDataArray *arr = out_pd->GetArray(i); output->GetPointData()->AddArray(arr); } output->GetPointData()->RemoveArray("InputPointIds"); out_pd->Delete(); ids->Delete(); ManageMemory(output); glyphFilter->Delete(); pdrp->Delete(); ugrp->Delete(); return output; }
vtkDataSet * avtLineoutFilter::NoSampling(vtkDataSet *in_ds, int domain) { bool rgrid = in_ds->GetDataObjectType() == VTK_RECTILINEAR_GRID; vtkDataSet *rv = NULL; // // Use interval tree to find intersected cells // int ncells = in_ds->GetNumberOfCells(); avtIntervalTree itree(ncells, ndims, false); double bounds[6]; double tol = 1e38; for (int i = 0; i < ncells; i++) { in_ds->GetCellBounds(i, bounds); itree.AddElement(i, bounds); double min = GetMinRange(bounds, ndims); if (min < tol) tol = min; } tol = tol/2.; itree.Calculate(); intVector isectedCells; doubleVector isectedPts; intVector lineCells; doubleVector linePts; itree.GetElementsListFromLine(point1, point2, lineCells, linePts, &tol); if (lineCells.size() == 0) { debug5 << "avtIntervalTree returned NO intersected cells for domain " << domain << "." << endl; return NULL; } vtkUnsignedCharArray *ghosts = (vtkUnsignedCharArray *)in_ds->GetCellData()->GetArray("avtGhostZones"); vtkCellIntersections *cellIntersections = NULL; vtkGenericCell *cell; double isect[3], p1[3], t; bool endPointInCell = false; if (!rgrid) { cellIntersections = vtkCellIntersections::New(); cellIntersections->SetTestCoPlanar(true); cell = vtkGenericCell::New(); } for (int i = 0; i < lineCells.size(); i++) { // // Want to skip ghost zones!! // if (ghosts && ghosts->GetComponent(lineCells[i], 0)) { continue; } bool doMore = true; if (!rgrid) { // // do a bit more checking if not a rectlinearGrid, as the interval // tree only calculated intersections with a cell's bounding box. // in_ds->GetCell(lineCells[i], cell); double isect2[3]; // Check both directions of the line, because we don't want // to intersect only a node. if (cellIntersections->CellIntersectWithLine(cell, point1, point2, t, isect) && cellIntersections->CellIntersectWithLine(cell, point2, point1, t, isect2)) { if (vtkVisItUtility::PointsEqual(isect, isect2, &tol)) { // Discard single-point intersections that are equivalent // to an endpoint. doMore = false; if (vtkVisItUtility::CellContainsPoint(cell, point1)) { if (!vtkVisItUtility::PointsEqual(point1, isect, &tol)) { p1[0] = point1[0]; p1[1] = point1[1]; p1[2] = point1[2]; doMore = true; } } else if (vtkVisItUtility::CellContainsPoint(cell, point2)) { if (!vtkVisItUtility::PointsEqual(point2, isect, &tol)) { p1[0] = point2[0]; p1[1] = point2[1]; p1[2] = point2[2]; doMore = true; } } } // points equal else { p1[0] = isect[0]; p1[1] = isect[1]; p1[2] = isect[2]; doMore = true; } } // isects both directions else { doMore = false; } } // rgrid else { p1[0] = linePts[i*3]; p1[1] = linePts[i*3+1]; p1[2] = linePts[i*3+2]; } if (doMore) { bool dupFound = false; for (int j = 0; j < isectedCells.size() && !dupFound; j++) { double p2[3]; p2[0] = isectedPts[j*3]; p2[1] = isectedPts[j*3+1]; p2[2] = isectedPts[j*3+2]; if (vtkVisItUtility::PointsEqual(p1, p2, &tol)) { dupFound = true; if (lineCells[i] < isectedCells[j]) isectedCells[j] = lineCells[i]; } } if (!dupFound) { isectedCells.push_back(lineCells[i]); isectedPts.push_back(p1[0]); isectedPts.push_back(p1[1]); isectedPts.push_back(p1[2]); } } } vtkIdList *cells = vtkIdList::New(); vtkPoints *pts = vtkVisItUtility::NewPoints(in_ds); double cpt[3]; for (int i = 0; i < isectedCells.size(); i++) { cpt[0] = isectedPts[i*3]; cpt[1] = isectedPts[i*3+1]; cpt[2] = isectedPts[i*3+2]; pts->InsertNextPoint(cpt); cells->InsertNextId(isectedCells[i]); } if (!useOriginalCells) { rv = CreateRGrid(in_ds, point1, point2, pts, cells); } else { rv = CreateRGridFromOrigCells(in_ds, point1, point2, pts, cells); } if (rv->GetNumberOfCells() == 0 || rv->GetNumberOfPoints() == 0) { debug5 << "avtIntervalTree returned empty DS for domain " << domain << "." << endl; rv = NULL; } cells->Delete(); pts->Delete(); if (!rgrid) { cellIntersections->Delete(); cell->Delete(); } ManageMemory(rv); if (rv != NULL) rv->Delete(); return rv; }
vtkDataSet * avtDeformSphereGlyphFilter::ExecuteData(vtkDataSet *in_ds, int, std::string) { // grab the input data vtkPointData *inPD = in_ds->GetPointData(); vtkCellData *inCD = in_ds->GetCellData(); vtkDataArray *data = inPD->GetArray(var.c_str()); bool pointVar = true; if (!data) { pointVar = false; data = inCD->GetArray(var.c_str()); } if (!data) EXCEPTION1(ImproperUseException, "Could not find variable"); if (data->GetNumberOfComponents() != geodesic_sphere_npts) EXCEPTION1(ImproperUseException, "Array variable had wrong " "number of components."); // get the scaling parameters double scale = atts.GetScale(); double minsize = atts.GetMinSize(); // set up the output data vtkPolyData *output = vtkPolyData::New(); vtkPoints *pts = vtkVisItUtility::NewPoints(in_ds); output->SetPoints(pts); pts->Delete(); vtkCellArray *polys = vtkCellArray::New(); output->SetPolys(polys); polys->Delete(); vtkPointData *outPD = output->GetPointData(); vtkCellData *outCD = output->GetCellData(); int nOutSpheres = pointVar ? in_ds->GetNumberOfPoints() : in_ds->GetNumberOfCells(); int nOutPoints = nOutSpheres * geodesic_sphere_npts; int nOutTris = nOutSpheres * geodesic_sphere_ntris; // It is meaningless to copy cell data if we're making our // spheres from a point array, and meaningless to copy point // data if we're making the sphered from a cell array. But // since later filters seem to blindly assume their requested // array will still exist, we'll just copy over the 0th input // value for all output data values in the meaningless cases.... outPD->CopyAllocate(inPD, nOutPoints); outCD->CopyAllocate(inCD, nOutTris); // actually greate the deformed spheres pts->SetNumberOfPoints(nOutPoints); for (int s = 0 ; s < nOutSpheres ; s++) { // calculate the center for the sphere double pt[3]; if (pointVar) { in_ds->GetPoint(s, pt); } else { pt[0] = pt[1] = pt[2] = 0.0; vtkCell *cell = in_ds->GetCell(s); int ncp = cell->GetNumberOfPoints(); for (int p=0; p<ncp; p++) { int id = cell->GetPointId(p); double *tp = in_ds->GetPoint(id); pt[0] += tp[0]; pt[1] += tp[1]; pt[2] += tp[2]; } pt[0] /= double(ncp); pt[1] /= double(ncp); pt[2] /= double(ncp); } // base index int baseptindex = s*geodesic_sphere_npts; // add the points double newpt[3]; for (int p=0; p<geodesic_sphere_npts; p++) { int newid = baseptindex+p; double factor = minsize + scale*data->GetComponent(s,p); newpt[0] = pt[0]+factor*geodesic_sphere_points[p][0]; newpt[1] = pt[1]+factor*geodesic_sphere_points[p][1]; newpt[2] = pt[2]+factor*geodesic_sphere_points[p][2]; output->GetPoints()->SetPoint(newid, newpt); if (pointVar) outPD->CopyData(inPD, s, newid); else outPD->CopyData(inPD, 0, newid); //meaningless } // add the tris vtkIdType tri[3]; for (int t=0; t<geodesic_sphere_ntris; t++) { tri[0] = baseptindex + geodesic_sphere_tris[t][0]; tri[1] = baseptindex + geodesic_sphere_tris[t][1]; tri[2] = baseptindex + geodesic_sphere_tris[t][2]; int newid = polys->InsertNextCell(3, tri); if (!pointVar) outCD->CopyData(inCD, s, newid); else outCD->CopyData(inCD, 0, newid); //meaningless } } // Don't keep the array variable! Total waste of space // now that we're done with it..... // (Ideally we shouldn't have copied it over at all, // but offhand I'm not sure how to easily prevent that.) if (pointVar) outPD->RemoveArray(var.c_str()); else outCD->RemoveArray(var.c_str()); ManageMemory(output); return output; }
vtkDataSet * avtIsovolumeFilter::ExecuteData(vtkDataSet *in_ds, int, std::string) { // // Start off by calculating the range of the dataset. // vtkDataArray *vals = NULL; if (in_ds->GetPointData()->GetScalars() != NULL) vals = in_ds->GetPointData()->GetScalars(); else if (in_ds->GetCellData()->GetScalars() != NULL) vals = in_ds->GetCellData()->GetScalars(); if (vals == NULL) return in_ds; double min, max; if(vals->GetDataType() == VTK_FLOAT) IsovolumeMinMax(min, max, avtDirectAccessor<float>(vals)); else if(vals->GetDataType() == VTK_DOUBLE) IsovolumeMinMax(min, max, avtDirectAccessor<double>(vals)); else IsovolumeMinMax(min, max, avtTupleAccessor(vals)); // // Check to see if our range is below the min or above the max. If so, // we will have an empty intersection. // if (max < atts.GetLbound() || min > atts.GetUbound()) { return NULL; } // // Determine if we need to do the min clip or max clip. Because of the // above logic, we can assume that the dataset's max is bigger than // the isovolume's lbound and the min is less than the ubound. // bool doMinClip = false; if ((atts.GetLbound() > -1e37) && (min < atts.GetLbound())) doMinClip = true; bool doMaxClip = false; if ((atts.GetUbound() < 1e37) && (max > atts.GetUbound())) doMaxClip = true; // // Do the clipping! // vtkDataSet *out_ds = in_ds; if (doMinClip) out_ds = ExecuteSingleClip(out_ds, atts.GetLbound(), true); if (doMaxClip) out_ds = ExecuteSingleClip(out_ds, atts.GetUbound(), false); // // Make sure there's something there // if (out_ds->GetNumberOfCells() <= 0) { out_ds = NULL; } // // If we had poly data input, we want poly data output. The VTK filter // only returns unstructured grids, so convert that now. Note: we don't // necessarily have a ugrid, since it might be that we didn't process the // dataset. // bool shouldDelete = false; if (in_ds->GetDataObjectType() == VTK_POLY_DATA && out_ds != NULL && out_ds->GetDataObjectType() == VTK_UNSTRUCTURED_GRID) { vtkUnstructuredGrid *ugrid = (vtkUnstructuredGrid *) out_ds; vtkPolyData *out_pd = vtkPolyData::New(); out_pd->SetPoints(ugrid->GetPoints()); out_pd->GetPointData()->ShallowCopy(ugrid->GetPointData()); out_pd->GetCellData()->ShallowCopy(ugrid->GetCellData()); vtkIdType ncells = ugrid->GetNumberOfCells(); out_pd->Allocate(ncells); for (vtkIdType i = 0 ; i < ncells ; i++) { int celltype = ugrid->GetCellType(i); vtkIdType *pts, npts; ugrid->GetCellPoints(i, npts, pts); out_pd->InsertNextCell(celltype, npts, pts); } out_ds = out_pd; shouldDelete = true; } ManageMemory(out_ds); if (shouldDelete) out_ds->Delete(); return out_ds; }
vtkDataSet * avtIsovolumeFilter::ExecuteSingleClip(vtkDataSet *in_ds, float val, bool flip) { vtkVisItClipper *clipper = vtkVisItClipper::New(); clipper->SetInsideOut(flip); // // Get the scalar array we'll use for clipping; it must be nodal // vtkCellDataToPointData *cd2pd = NULL; if (in_ds->GetPointData()->GetScalars()) { vtkDataArray *s = in_ds->GetPointData()->GetScalars(); clipper->SetClipScalars(s, val); } else if (in_ds->GetCellData()->GetScalars()) { // // Okay, our active variable was cell-centered. Recenter it.... // vtkDataSet *temp_ds = (vtkDataSet *) in_ds->NewInstance(); temp_ds->CopyStructure(in_ds); temp_ds->GetCellData()->SetScalars(in_ds->GetCellData()->GetScalars()); cd2pd = vtkCellDataToPointData::New(); cd2pd->SetInput(temp_ds); cd2pd->Update(); vtkDataSet *temporary = cd2pd->GetOutput(); // Now tell the clipper about it.... vtkDataArray *s = temporary->GetPointData()->GetScalars(); clipper->SetClipScalars(s, val); // Wait until after the clipping is done to delete 'cd2pd' (which // will take 'temporary' with it) temp_ds->Delete(); } else { debug1 << "Could not find any data for isovolume operation\n"; EXCEPTION1(VisItException, "No variable was present for the Isovolume"); } // // Do the clipping! // vtkDataSet *out_ds; clipper->SetInput(in_ds); out_ds = clipper->GetOutput(); out_ds->Update(); ManageMemory(out_ds); clipper->Delete(); // // Free the temporary filter used to convert to point data // if (cd2pd) cd2pd->Delete(); return out_ds; }