1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkQuadraturePointInterpolator.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkQuadraturePointInterpolator.h"
#include "vtkQuadratureSchemeDefinition.h"
#include "vtkUnstructuredGrid.h"
#include "vtkPolyData.h"
#include "vtkPoints.h"
#include "vtkType.h"
#include "vtkDoubleArray.h"
#include "vtkDataArray.h"
#include "vtkPointData.h"
#include "vtkCellData.h"
#include "vtkCellType.h"
#include "vtkCellArray.h"
#include "vtkIdTypeArray.h"
#include "vtkIntArray.h"
#include "vtkUnstructuredGridAlgorithm.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkInformationQuadratureSchemeDefinitionVectorKey.h"
#include "vtkObjectFactory.h"
#include <sstream>
using std::ostringstream;
#include "vtkQuadraturePointsUtilities.hxx"
vtkStandardNewMacro(vtkQuadraturePointInterpolator);
//-----------------------------------------------------------------------------
vtkQuadraturePointInterpolator::vtkQuadraturePointInterpolator()
{
this->Clear();
this->SetNumberOfInputPorts(1);
this->SetNumberOfOutputPorts(1);
}
//-----------------------------------------------------------------------------
vtkQuadraturePointInterpolator::~vtkQuadraturePointInterpolator()
{
this->Clear();
}
//-----------------------------------------------------------------------------
int vtkQuadraturePointInterpolator::FillInputPortInformation(
int port,
vtkInformation *info)
{
switch (port)
{
case 0:
info->Set(vtkDataObject::DATA_TYPE_NAME(),"vtkUnstructuredGrid");
break;
}
return 1;
}
//-----------------------------------------------------------------------------
int vtkQuadraturePointInterpolator::FillOutputPortInformation(
int port,
vtkInformation *info)
{
switch (port)
{
case 0:
info->Set(vtkDataObject::DATA_TYPE_NAME(),"vtkUnstructuredGrid");
break;
}
return 1;
}
//-----------------------------------------------------------------------------
int vtkQuadraturePointInterpolator::RequestData(
vtkInformation *,
vtkInformationVector **input,
vtkInformationVector *output)
{
vtkDataObject *tmpDataObj;
// Get the inputs
tmpDataObj
= input[0]->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT());
vtkUnstructuredGrid *usgIn
= vtkUnstructuredGrid::SafeDownCast(tmpDataObj);
// Get the outputs
tmpDataObj
= output->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT());
vtkUnstructuredGrid *usgOut
= vtkUnstructuredGrid::SafeDownCast(tmpDataObj);
// Quick sanity check.
if (usgIn==NULL || usgOut==NULL
|| usgIn->GetNumberOfCells()==0
|| usgIn->GetNumberOfPoints()==0
|| usgIn->GetPointData()==NULL
|| usgIn->GetPointData()->GetNumberOfArrays()==0)
{
vtkWarningMacro("Filter data has not been configured correctly. Aborting.");
return 1;
}
// Copy the unstructured grid on the input
usgOut->ShallowCopy(usgIn);
// Interpolate the data arrays, but no points. Results
// are stored in field data arrays.
this->InterpolateFields(usgOut);
return 1;
}
//-----------------------------------------------------------------------------
void vtkQuadraturePointInterpolator::Clear()
{
// Nothing to do
}
//-----------------------------------------------------------------------------
int vtkQuadraturePointInterpolator::InterpolateFields(
vtkUnstructuredGrid *usgOut)
{
// Extract info we need for all cells.
vtkIdType nCells=usgOut->GetNumberOfCells();
// For each array we interpolate scalar data to the
// integration point location. Results are in associated
// field data arrays.
int nArrays
= usgOut->GetPointData()->GetNumberOfArrays();
vtkDataArray *offsets=this->GetInputArrayToProcess(0,usgOut);
if(offsets == NULL)
{
vtkWarningMacro("no Offset array, skipping.");
return 0;
}
const char* arrayOffsetName = offsets->GetName();
void *pOffsets = offsets->GetVoidPointer(0);
int O_Type = offsets->GetDataType();
vtkInformation *info=offsets->GetInformation();
vtkInformationQuadratureSchemeDefinitionVectorKey *key=vtkQuadratureSchemeDefinition::DICTIONARY();
if (!key->Has(info))
{
vtkWarningMacro("Dictionary is not present in. Skipping.");
return 0;
}
int dictSize= key->Size(info);
vtkQuadratureSchemeDefinition **dict=new vtkQuadratureSchemeDefinition *[dictSize];
key->GetRange(info,dict,0,0,dictSize);
// interpolate the arrays
for (int arrayId=0; arrayId<nArrays; ++arrayId)
{
// Grab the next array
vtkDataArray *V=usgOut->GetPointData()->GetArray(arrayId);
int V_type=V->GetDataType();
void *pV=V->GetVoidPointer(0);
// Use two arrays, one with the interpolated values,
// the other with offsets to the start of each cell's
// interpolated values.
int nComps=V->GetNumberOfComponents();
vtkDoubleArray *interpolated=vtkDoubleArray::New();
interpolated->SetNumberOfComponents(nComps);
interpolated->CopyComponentNames( V );
interpolated->Allocate(nComps*nCells); // at least one qp per cell
ostringstream interpolatedName;
interpolatedName << V->GetName();// << "_QP_Interpolated";
interpolated->SetName(interpolatedName.str().c_str());
usgOut->GetFieldData()->AddArray(interpolated);
interpolated->GetInformation()->Set(
vtkQuadratureSchemeDefinition::QUADRATURE_OFFSET_ARRAY_NAME(),
arrayOffsetName);
interpolated->Delete();
// For all cells interpolate.
switch (V_type)
{
vtkTemplateMacro(
if (!Interpolate(
usgOut,
nCells,
static_cast<VTK_TT*>(pV),
nComps,
dict,
interpolated,
pOffsets,
O_Type))
{
vtkWarningMacro("Failed to interpolate fields "
"to quadrature points. Aborting.");
return 0;
}
);
}
}
delete [] dict;
return 1;
}
//-----------------------------------------------------------------------------
void vtkQuadraturePointInterpolator::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "No state." << endl;
}
|