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(
const eq::Matrix4d& modelviewM,
74 const double newSliceDistance,
75 const eq::Range& range
78 double zRs = -1+2.*range.start;
79 double zRe = -1+2.*range.end;
82 eq::Vector4d vertices[8];
83 vertices[0] = eq::Vector4d(-1.0,-1.0,zRs, 1.0);
84 vertices[1] = eq::Vector4d( 1.0,-1.0,zRs, 1.0);
85 vertices[2] = eq::Vector4d(-1.0, 1.0,zRs, 1.0);
86 vertices[3] = eq::Vector4d( 1.0, 1.0,zRs, 1.0);
88 vertices[4] = eq::Vector4d(-1.0,-1.0,zRe, 1.0);
89 vertices[5] = eq::Vector4d( 1.0,-1.0,zRe, 1.0);
90 vertices[6] = eq::Vector4d(-1.0, 1.0,zRe, 1.0);
91 vertices[7] = eq::Vector4d( 1.0, 1.0,zRe, 1.0);
93 for(
int i=0; i<8; i++ )
94 for(
int j=0; j<3; j++)
95 shaderVertices[ i*3+j ] =
float( vertices[i][j] );
98 this->viewVec = eq::Vector4d( -modelviewM.array[ 2],
99 -modelviewM.array[ 6],
100 -modelviewM.array[10],
103 viewVecf = eq::Vector3f(
float( viewVec.x( )),
float( viewVec.y( )),
104 float( viewVec.z( )));
106 sliceDistance = newSliceDistance;
109 float maxDist = float( viewVec.dot( vertices[0] ));
110 for(
int i = 1; i < 8; i++ )
112 const float dist = float( viewVec.dot( vertices[i] ));
120 planeStart = viewVec.dot( vertices[nSequence[frontIndex][0]] );
121 double dS = ceil( planeStart/sliceDistance );
122 planeStart = dS * sliceDistance;
126 eq::Vector3f SliceClipper::getPosition
132 const float dPlaneDist = float( planeStart + sliceNum * sliceDistance );
133 float3 Position = float3( 0.0, 0.0, 0.0 );
135 for(
int e = 0; e < 4; e++ )
137 int vidx1 = 3*
static_cast<int>( sequence[
138 static_cast<int>(frontIndex * 8 + v1[vertexNum*4+e])]);
139 int vidx2 = 3*
static_cast<int>( sequence[
140 static_cast<int>(frontIndex * 8 + v2[vertexNum*4+e])]);
142 float3 vecV1( shaderVertices[vidx1 ],
143 shaderVertices[vidx1+1],
144 shaderVertices[vidx1+2] );
146 float3 vecV2( shaderVertices[vidx2 ],
147 shaderVertices[vidx2+1],
148 shaderVertices[vidx2+2] );
150 float3 vecStart = vecV1;
151 float3 vecDir = vecV2-vecV1;
153 float denom = vecDir.dot( viewVecf );
154 float lambda = (denom != 0.0f) ?
155 (dPlaneDist - vecStart.dot(viewVecf))/denom : -1.0f;
157 if(( lambda >= 0.0f ) && ( lambda <= 1.0f ))
159 Position = vecStart + vecDir * lambda;