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
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkDashedStreamLine.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 "vtkDashedStreamLine.h"
#ifndef VTK_LEGACY_REMOVE
#include "vtkCellArray.h"
#include "vtkDataSet.h"
#include "vtkFloatArray.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPolyData.h"
vtkStandardNewMacro(vtkDashedStreamLine);
vtkDashedStreamLine::vtkDashedStreamLine()
{
this->DashFactor = 0.75;
VTK_LEGACY_BODY(vtkDashedStreamLine::vtkDashedStreamLine, "VTK 6.3");
}
int vtkDashedStreamLine::RequestData(vtkInformation *,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
vtkInformation *outInfo = outputVector->GetInformationObject(0);
vtkInformation *sourceInfo = inputVector[1]->GetInformationObject(0);
vtkStreamer::StreamPoint *sPrev, *sPtr;
vtkPoints *newPts;
vtkFloatArray *newVectors;
vtkFloatArray *newScalars=NULL;
vtkCellArray *newLines;
int i, ptId, j;
vtkIdType pts[2];
double tOffset, x[3], v[3], r, xPrev[3], vPrev[3], scalarPrev;
double s = 0;
double xEnd[3], vEnd[3], sEnd;
vtkDataSet *input = vtkDataSet::SafeDownCast(
inInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkPolyData *output = vtkPolyData::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkDataSet *source = 0;
if (sourceInfo)
{
source = vtkDataSet::SafeDownCast(
sourceInfo->Get(vtkDataObject::DATA_OBJECT()));
}
this->SavePointInterval = this->StepLength;
this->vtkStreamer::Integrate(input, source);
if ( this->NumberOfStreamers <= 0 )
{
return 1;
}
//
// Convert streamer into lines. Lines may be dashed.
//
newPts = vtkPoints::New();
newPts->Allocate(1000);
newVectors = vtkFloatArray::New();
newVectors->SetNumberOfComponents(3);
newVectors->Allocate(1000);
if ( input->GetPointData()->GetScalars() || this->SpeedScalars )
{
newScalars = vtkFloatArray::New();
newScalars->Allocate(1000);
}
newLines = vtkCellArray::New();
newLines->Allocate(newLines->EstimateSize(2*this->NumberOfStreamers,VTK_CELL_SIZE));
//
// Loop over all streamers generating points
//
for (ptId=0; ptId < this->NumberOfStreamers; ptId++)
{
if ( this->Streamers[ptId].GetNumberOfPoints() < 2 )
{
continue;
}
sPrev = this->Streamers[ptId].GetStreamPoint(0);
sPtr = this->Streamers[ptId].GetStreamPoint(1);
for (j=0; j<3; j++)
{
xPrev[j] = sPrev->x[j];
vPrev[j] = sPrev->v[j];
}
scalarPrev = sPrev->s;
if ( this->Streamers[ptId].GetNumberOfPoints() == 2 && sPtr->cellId < 0 )
{
continue;
}
tOffset = sPrev->t;
for ( i=1;
i < this->Streamers[ptId].GetNumberOfPoints() && sPtr->cellId >= 0;
i++, sPrev=sPtr, sPtr=this->Streamers[ptId].GetStreamPoint(i) )
{
//
// Search for end of dash...create end of one dash, beginning of next
//
while ( tOffset >= sPrev->t && tOffset < sPtr->t )
{
r = (tOffset - sPrev->t) / (sPtr->t - sPrev->t);
for (j=0; j<3; j++)
{
x[j] = sPrev->x[j] + r * (sPtr->x[j] - sPrev->x[j]);
v[j] = sPrev->v[j] + r * (sPtr->v[j] - sPrev->v[j]);
xEnd[j] = xPrev[j] + this->DashFactor * (x[j] - xPrev[j]);
vEnd[j] = vPrev[j] + this->DashFactor * (v[j] - vPrev[j]);
}
// create this dash
pts[0] = newPts->InsertNextPoint(x);
newVectors->InsertTuple(pts[0],v);
pts[1] = newPts->InsertNextPoint(xEnd);
newVectors->InsertTuple(pts[1],vEnd);
if ( newScalars )
{
s = sPrev->s + r * (sPtr->s - sPrev->s);
newScalars->InsertTuple(pts[0],&s);
sEnd = scalarPrev + this->DashFactor * (s - scalarPrev);
newScalars->InsertTuple(pts[1],&sEnd);
}
newLines->InsertNextCell(2,pts);
for (j=0; j<3; j++)
{
xPrev[j] = x[j];
vPrev[j] = v[j];
}
if ( newScalars )
{
scalarPrev = s;
}
tOffset += this->StepLength;
} // while
} //for this streamer
} //for all streamers
//
// Update ourselves and release memory
//
vtkDebugMacro(<<"Created " << newPts->GetNumberOfPoints() << " points, "
<< newLines->GetNumberOfCells() << " lines");
output->SetPoints(newPts);
newPts->Delete();
output->GetPointData()->SetVectors(newVectors);
newVectors->Delete();
if ( newScalars )
{
int idx = output->GetPointData()->AddArray(newScalars);
output->GetPointData()->SetActiveAttribute(idx,
vtkDataSetAttributes::SCALARS);
newScalars->Delete();
}
output->SetLines(newLines);
newLines->Delete();
// Delete the streamers since they are no longer needed
delete[] this->Streamers;
this->Streamers = 0;
this->NumberOfStreamers = 0;
output->Squeeze();
return 1;
}
void vtkDashedStreamLine::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Dash Factor: " << this->DashFactor << " <<\n";
}
#endif // VTK_LEGACY_REMOVE
|