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
|
/*
* Copyright 2003 Sandia Corporation.
* Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
* license for use of this work by or on behalf of the
* U.S. Government. Redistribution and use in source and binary forms, with
* or without modification, are permitted provided that this Notice and any
* statement of authorship are reproduced on all copies.
*/
#include "vtkEdgeSubdivisionCriterion.h"
#include "vtkStreamingTessellator.h"
#include "vtkDataSetAttributes.h"
#include "vtkMatrix4x4.h"
void vtkEdgeSubdivisionCriterion::PrintSelf( ostream& os, vtkIndent indent )
{
this->Superclass::PrintSelf( os, indent );
}
vtkEdgeSubdivisionCriterion::vtkEdgeSubdivisionCriterion()
{
this->FieldIds = new int [ vtkStreamingTessellator::MaxFieldSize ];
this->FieldOffsets = new int [ vtkStreamingTessellator::MaxFieldSize + 1 ];
this->FieldOffsets[0] = 0;
this->NumberOfFields = 0;
}
vtkEdgeSubdivisionCriterion::~vtkEdgeSubdivisionCriterion()
{
delete[] this->FieldIds;
delete[] this->FieldOffsets;
};
void vtkEdgeSubdivisionCriterion::ResetFieldList()
{
this->NumberOfFields = 0;
}
int vtkEdgeSubdivisionCriterion::PassField( int sourceId, int sourceSize, vtkStreamingTessellator* t )
{
if ( sourceSize + this->FieldOffsets[ this->NumberOfFields ] > vtkStreamingTessellator::MaxFieldSize )
{
vtkErrorMacro( "PassField source size (" << sourceSize << ") was too large for vtkStreamingTessellator" );
}
int off = this->GetOutputField( sourceId );
if ( off == -1 )
{
this->FieldIds[ this->NumberOfFields ] = sourceId;
off = this->FieldOffsets[ this->NumberOfFields ];
t->SetFieldSize( -1, this->FieldOffsets[ ++this->NumberOfFields ] = off + sourceSize );
this->Modified();
}
else
{
off = this->FieldOffsets[ off ];
vtkWarningMacro( "Field " << sourceId << " is already being passed as offset " << off << "." );
}
return off;
}
bool vtkEdgeSubdivisionCriterion::DontPassField( int sourceId, vtkStreamingTessellator* t )
{
int id = this->GetOutputField( sourceId );
if ( id == -1 )
return false;
int sz = this->FieldOffsets[id+1] - this->FieldOffsets[id];
for ( int i=id+1; i<this->GetNumberOfFields(); ++i )
{
this->FieldIds[i-1] = this->FieldIds[i];
this->FieldOffsets[i] = this->FieldOffsets[i+1] - sz;
}
t->SetFieldSize( -1, this->FieldOffsets[ this->GetNumberOfFields() ] );
this->Modified();
return true;
}
int vtkEdgeSubdivisionCriterion::GetOutputField( int sourceId ) const
{
for ( int i=0; i<this->NumberOfFields; ++i )
if ( this->FieldIds[i] == sourceId )
return i;
return -1;
}
bool vtkEdgeSubdivisionCriterion::ViewDependentEval(
const double* p0, double* p1, double* real_p1,
const double* p2, int ,
vtkMatrix4x4* Transform, const double* PixelSize,
double AllowableChordError ) const
{
double real_p1t[4];
double intr_p1t[4];
Transform->MultiplyPoint( real_p1, real_p1t );
Transform->MultiplyPoint( p1, intr_p1t );
double eprod = fabs(AllowableChordError*real_p1t[3]*intr_p1t[3]);
/*
fprintf( stderr, "eprod=%g, compare to <%g,%g>\n", eprod,
fabs(real_p1t[0]*intr_p1t[3]-intr_p1t[0]*real_p1t[3])/PixelSize[0],
fabs(real_p1t[1]*intr_p1t[3]-intr_p1t[1]*real_p1t[3])/PixelSize[1] );
*/
if ( (real_p1t[0] > real_p1t[3]) || (real_p1t[0] < -real_p1t[3]) ||
(real_p1t[1] > real_p1t[3]) || (real_p1t[1] < -real_p1t[3]) ) {
double p0t[4];
double p2t[4];
for (int i=0; i<3; i++) {
p0t[i] = p0[i];
p2t[i] = p2[i];
}
p0t[3] = p2t[3] = 1.;
Transform->MultiplyPoint( p0t, p0t );
Transform->MultiplyPoint( p2t, p2t );
int p0Code=0, p2Code=0;
#define ENDPOINT_CODE(code,pt) \
if ( pt[0] > pt[3] ) \
code += 1; \
else if ( pt[0] < -pt[3] ) \
code += 2; \
if ( pt[1] > pt[3] ) \
code += 4; \
else if ( pt[1] < -pt[3] ) \
code += 8;
ENDPOINT_CODE(p0Code,p0t);
ENDPOINT_CODE(p2Code,p2t);
if ( p0Code & p2Code ) {
return false ;
}
}
if ( fabs(real_p1t[0]*intr_p1t[3]-intr_p1t[0]*real_p1t[3])/PixelSize[0] > eprod ||
fabs(real_p1t[1]*intr_p1t[3]-intr_p1t[1]*real_p1t[3])/PixelSize[1] > eprod ) {
// copy the properly interpolated point into the result
for ( int c=0; c<3; ++c )
p1[c] = real_p1[c];
return true ; // need to subdivide
}
return false ; // no need to subdivide
}
bool vtkEdgeSubdivisionCriterion::FixedFieldErrorEval( const double*, double* p1, double* real_pf, const double*, int field_start, int criteria, double* AllowableL2Error2 ) const
{
int id = 0;
double mag;
while ( criteria )
{
if ( ! (criteria & 1) )
{
criteria >>= 1;
++id;
continue;
}
mag = 0.;
int fsz = this->FieldOffsets[id+1] - this->FieldOffsets[id];
for ( int c=0; c<fsz; ++c )
{
double tmp = real_pf[c+field_start] - p1[c+field_start];
mag += tmp*tmp;
}
if ( mag > AllowableL2Error2[id] )
{
return true;
}
criteria >>= 1;
++id;
}
return false;
}
|