00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "sliceClipping.h"
00019
00020
00021 namespace eVolve
00022 {
00023
00024 const int SliceClipper::nSequence[8][8] = {
00025 {7,3,5,6,1,2,4,0},
00026 {6,2,4,7,0,3,5,1},
00027 {5,1,4,7,0,3,6,2},
00028 {4,0,5,6,1,2,7,3},
00029 {3,1,2,7,0,5,6,4},
00030 {2,0,3,6,1,4,7,5},
00031 {1,0,3,5,2,4,7,6},
00032 {0,1,2,4,3,5,6,7},
00033 };
00034
00035 const float SliceClipper::sequence[64] = {
00036 0, 1, 4, 2, 3, 5, 6, 7,
00037 1, 0, 3, 5, 4, 2, 7, 6,
00038 2, 0, 6, 3, 1, 4, 7, 5,
00039 3, 1, 2, 7, 5, 0, 6, 4,
00040 4, 0, 5, 6, 2, 1, 7, 3,
00041 5, 1, 7, 4, 0, 3, 6, 2,
00042 6, 2, 4, 7, 3, 0, 5, 1,
00043 7, 3, 6, 5, 1, 2, 4, 0 };
00044
00045 const float SliceClipper::v1[24] = {
00046 0, 1, 4, 4,
00047 1, 0, 1, 4,
00048 0, 2, 5, 5,
00049 2, 0, 2, 5,
00050 0, 3, 6, 6,
00051 3, 0, 3, 6 };
00052
00053 const float SliceClipper::v2[24] = {
00054 1, 4, 7, 7,
00055 5, 1, 4, 7,
00056 2, 5, 7, 7,
00057 6, 2, 5, 7,
00058 3, 6, 7, 7,
00059 4, 3, 6, 7 };
00060
00061
00062 void SliceClipper::updatePerFrameInfo
00063 (
00064 const eq::Matrix4d& modelviewM,
00065 const eq::Matrix3d& modelviewITM,
00066 const double newSliceDistance,
00067 const eq::Range& range
00068 )
00069 {
00070 double zRs = -1+2.*range.start;
00071 double zRe = -1+2.*range.end;
00072
00073
00074 eq::Vector4d vertices[8];
00075 vertices[0] = eq::Vector4d(-1.0,-1.0,zRs, 1.0);
00076 vertices[1] = eq::Vector4d( 1.0,-1.0,zRs, 1.0);
00077 vertices[2] = eq::Vector4d(-1.0, 1.0,zRs, 1.0);
00078 vertices[3] = eq::Vector4d( 1.0, 1.0,zRs, 1.0);
00079
00080 vertices[4] = eq::Vector4d(-1.0,-1.0,zRe, 1.0);
00081 vertices[5] = eq::Vector4d( 1.0,-1.0,zRe, 1.0);
00082 vertices[6] = eq::Vector4d(-1.0, 1.0,zRe, 1.0);
00083 vertices[7] = eq::Vector4d( 1.0, 1.0,zRe, 1.0);
00084
00085 for( int i=0; i<8; i++ )
00086 for( int j=0; j<3; j++)
00087 shaderVertices[ i*3+j ] = vertices[i][j];
00088
00089
00090 this->viewVec = eq::Vector4d( -modelviewM.array[ 2],
00091 -modelviewM.array[ 6],
00092 -modelviewM.array[10],
00093 0.0 );
00094
00095 viewVecf = eq::Vector3f( viewVec.x(), viewVec.y(), viewVec.z() );
00096
00097 sliceDistance = newSliceDistance;
00098
00099 frontIndex = 0;
00100 float maxDist = viewVec.dot( vertices[0] );
00101 for( int i = 1; i < 8; i++ )
00102 {
00103 float dist = viewVec.dot( vertices[i] );
00104 if ( dist > maxDist)
00105 {
00106 maxDist = dist;
00107 frontIndex = i;
00108 }
00109 }
00110
00111 planeStart = viewVec.dot( vertices[nSequence[frontIndex][0]] );
00112 double dS = ceil( planeStart/sliceDistance );
00113 planeStart = dS * sliceDistance;
00114 }
00115
00116
00117 eq::Vector3f SliceClipper::getPosition
00118 (
00119 const int vertexNum,
00120 const int sliceNum
00121 ) const
00122 {
00123 float dPlaneDist = planeStart + sliceNum * sliceDistance;
00124 float3 Position = float3( 0.0, 0.0, 0.0 );
00125
00126 for( int e = 0; e < 4; e++ )
00127 {
00128 int vidx1 = 3*static_cast<int>( sequence[
00129 static_cast<int>(frontIndex * 8 + v1[vertexNum*4+e])]);
00130 int vidx2 = 3*static_cast<int>( sequence[
00131 static_cast<int>(frontIndex * 8 + v2[vertexNum*4+e])]);
00132
00133 float3 vecV1( shaderVertices[vidx1 ],
00134 shaderVertices[vidx1+1],
00135 shaderVertices[vidx1+2] );
00136
00137 float3 vecV2( shaderVertices[vidx2 ],
00138 shaderVertices[vidx2+1],
00139 shaderVertices[vidx2+2] );
00140
00141 float3 vecStart = vecV1;
00142 float3 vecDir = vecV2-vecV1;
00143
00144 float denom = vecDir.dot( viewVecf );
00145 float lambda =
00146 (denom != 0.0) ? (dPlaneDist - vecStart.dot(viewVecf))/denom : -1.0;
00147
00148 if(( lambda >= 0.0 ) && ( lambda <= 1.0 ))
00149 {
00150 Position = vecStart + vecDir * lambda;
00151 break;
00152 }
00153 }
00154 return Position;
00155 }
00156
00157
00158 }
00159