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
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkSMPWarpVector.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 "vtkSMPWarpVector.h"
#include "vtkCellData.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkSMPTools.h"
#include "vtkPointData.h"
#include "vtkPointSet.h"
#include "vtkPoints.h"
//----------------------------------------------------------------------------
vtkStandardNewMacro(vtkSMPWarpVector);
//----------------------------------------------------------------------------
vtkSMPWarpVector::vtkSMPWarpVector()
{
this->ScaleFactor = 1.0;
// by default process active point vectors
this->SetInputArrayToProcess(0,0,0,vtkDataObject::FIELD_ASSOCIATION_POINTS,
vtkDataSetAttributes::VECTORS);
}
//----------------------------------------------------------------------------
vtkSMPWarpVector::~vtkSMPWarpVector()
{
}
//----------------------------------------------------------------------------
template <class T1, class T2>
class vtkSMPWarpVectorOp
{
public:
T1 *InPoints;
T1 *OutPoints;
T2 *InVector;
T1 scaleFactor;
void operator()(vtkIdType begin, vtkIdType end)
{
T1* inPts = this->InPoints + 3*begin;
T1* outPts = this->OutPoints + 3*begin;
T2* inVec = this->InVector + 3*begin;
T1 sf = this->scaleFactor;
vtkIdType size = 3*(end-begin);
vtkIdType nend = begin + size;
for (vtkIdType index = begin; index < nend; index++)
{
*outPts = *inPts + sf * (T1)(*inVec);
inPts++; outPts++; inVec++;
/*
*outPts = *inPts + sf * (T1)(*inVec);
inPts++; outPts++; inVec++;
*outPts = *inPts + sf * (T1)(*inVec);
inPts++; outPts++; inVec++;
*/
}
}
};
//----------------------------------------------------------------------------
template <class T1, class T2>
void vtkSMPWarpVectorExecute2(vtkSMPWarpVector *self,
T1 *inIter,
T1 *outIter,
T2 *inVecIter,
vtkIdType size)
{
vtkSMPWarpVectorOp<T1, T2> op;
op.InPoints = inIter;
op.OutPoints = outIter;
op.InVector = inVecIter;
op.scaleFactor = (T1)self->GetScaleFactor();
vtkSMPTools::For(0, size, op);
}
//----------------------------------------------------------------------------
template <class T>
void vtkSMPWarpVectorExecute(vtkSMPWarpVector *self,
T *inIter,
T *outIter,
vtkIdType size,
vtkDataArray *vectors)
{
void *inVecIter = vectors->GetVoidPointer(0);
// call templated function
switch (vectors->GetDataType())
{
vtkTemplateMacro(
vtkSMPWarpVectorExecute2(self, inIter, outIter,
(VTK_TT *)(inVecIter), size));
default:
break;
}
}
//----------------------------------------------------------------------------
int vtkSMPWarpVector::RequestData(
vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
// get the info objects
vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
vtkInformation *outInfo = outputVector->GetInformationObject(0);
// get the input and output
vtkPointSet *input = vtkPointSet::SafeDownCast(
inInfo->Get(vtkDataObject::DATA_OBJECT()));
if (!input)
{
// Let the superclass handle vtkImageData and vtkRectilinearGrid
return this->Superclass::RequestData(request, inputVector, outputVector);
}
vtkPointSet *output = vtkPointSet::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkPoints *points;
vtkIdType numPts;
// First, copy the input to the output as a starting point
output->CopyStructure( input );
if (input == NULL || input->GetPoints() == NULL)
{
return 1;
}
numPts = input->GetPoints()->GetNumberOfPoints();
vtkDataArray *vectors = this->GetInputArrayToProcess(0,inputVector);
if ( !vectors || !numPts)
{
vtkDebugMacro(<<"No input data");
return 1;
}
// SETUP AND ALLOCATE THE OUTPUT
numPts = input->GetNumberOfPoints();
points = input->GetPoints()->NewInstance();
points->SetDataType(input->GetPoints()->GetDataType());
points->Allocate(numPts);
points->SetNumberOfPoints(numPts);
output->SetPoints(points);
points->Delete();
vtkDataArray* inpts = input->GetPoints()->GetData();
vtkDataArray* outpts = output->GetPoints()->GetData();
void* inIter = inpts->GetVoidPointer(0);
void* outIter = outpts->GetVoidPointer(0);
// call templated function
switch (input->GetPoints()->GetDataType())
{
vtkTemplateMacro(
vtkSMPWarpVectorExecute(this,
(VTK_TT *)(inIter),
(VTK_TT *)(outIter),
numPts,
vectors));
default:
break;
}
// now pass the data.
output->GetPointData()->CopyNormalsOff(); // distorted geometry
output->GetPointData()->PassData(input->GetPointData());
output->GetCellData()->PassData(input->GetCellData());
return 1;
}
//----------------------------------------------------------------------------
void vtkSMPWarpVector::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Scale Factor: " << this->ScaleFactor << "\n";
}
|