29 #include "sliceClipping.h"
35 const int SliceClipper::nSequence[8][8] = {
46 const float SliceClipper::sequence[64] = {
47 0, 1, 4, 2, 3, 5, 6, 7,
48 1, 0, 3, 5, 4, 2, 7, 6,
49 2, 0, 6, 3, 1, 4, 7, 5,
50 3, 1, 2, 7, 5, 0, 6, 4,
51 4, 0, 5, 6, 2, 1, 7, 3,
52 5, 1, 7, 4, 0, 3, 6, 2,
53 6, 2, 4, 7, 3, 0, 5, 1,
54 7, 3, 6, 5, 1, 2, 4, 0 };
56 const float SliceClipper::v1[24] = {
64 const float SliceClipper::v2[24] = {
73 void SliceClipper::updatePerFrameInfo
75 const eq::Matrix4d& modelviewM,
76 const eq::Matrix3d& modelviewITM,
77 const double newSliceDistance,
78 const eq::Range& range
81 double zRs = -1+2.*range.start;
82 double zRe = -1+2.*range.end;
85 eq::Vector4d vertices[8];
86 vertices[0] = eq::Vector4d(-1.0,-1.0,zRs, 1.0);
87 vertices[1] = eq::Vector4d( 1.0,-1.0,zRs, 1.0);
88 vertices[2] = eq::Vector4d(-1.0, 1.0,zRs, 1.0);
89 vertices[3] = eq::Vector4d( 1.0, 1.0,zRs, 1.0);
91 vertices[4] = eq::Vector4d(-1.0,-1.0,zRe, 1.0);
92 vertices[5] = eq::Vector4d( 1.0,-1.0,zRe, 1.0);
93 vertices[6] = eq::Vector4d(-1.0, 1.0,zRe, 1.0);
94 vertices[7] = eq::Vector4d( 1.0, 1.0,zRe, 1.0);
96 for(
int i=0; i<8; i++ )
97 for(
int j=0; j<3; j++)
98 shaderVertices[ i*3+j ] =
float( vertices[i][j] );
101 this->viewVec = eq::Vector4d( -modelviewM.array[ 2],
102 -modelviewM.array[ 6],
103 -modelviewM.array[10],
106 viewVecf = eq::Vector3f(
float( viewVec.x( )),
float( viewVec.y( )),
107 float( viewVec.z( )));
109 sliceDistance = newSliceDistance;
112 float maxDist = float( viewVec.dot( vertices[0] ));
113 for(
int i = 1; i < 8; i++ )
115 const float dist = float( viewVec.dot( vertices[i] ));
123 planeStart = viewVec.dot( vertices[nSequence[frontIndex][0]] );
124 double dS = ceil( planeStart/sliceDistance );
125 planeStart = dS * sliceDistance;
129 eq::Vector3f SliceClipper::getPosition
135 const float dPlaneDist = float( planeStart + sliceNum * sliceDistance );
136 float3 Position = float3( 0.0, 0.0, 0.0 );
138 for(
int e = 0; e < 4; e++ )
140 int vidx1 = 3*
static_cast<int>( sequence[
141 static_cast<int>(frontIndex * 8 + v1[vertexNum*4+e])]);
142 int vidx2 = 3*
static_cast<int>( sequence[
143 static_cast<int>(frontIndex * 8 + v2[vertexNum*4+e])]);
145 float3 vecV1( shaderVertices[vidx1 ],
146 shaderVertices[vidx1+1],
147 shaderVertices[vidx1+2] );
149 float3 vecV2( shaderVertices[vidx2 ],
150 shaderVertices[vidx2+1],
151 shaderVertices[vidx2+2] );
153 float3 vecStart = vecV1;
154 float3 vecDir = vecV2-vecV1;
156 float denom = vecDir.dot( viewVecf );
157 float lambda = (denom != 0.0f) ?
158 (dPlaneDist - vecStart.dot(viewVecf))/denom : -1.0f;
160 if(( lambda >= 0.0f ) && ( lambda <= 1.0f ))
162 Position = vecStart + vecDir * lambda;