Equalizer  1.8.0
Parallel Rendering Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
sliceClipping.cpp
1 
2 /* Copyright (c) 2007 Maxim Makhinya
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * - Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  * - Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  * - Neither the name of Eyescale Software GmbH nor the names of its
13  * contributors may be used to endorse or promote products derived from this
14  * software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include "sliceClipping.h"
30 
31 
32 namespace eVolve
33 {
34 
35  const int SliceClipper::nSequence[8][8] = {
36  {7,3,5,6,1,2,4,0},
37  {6,2,4,7,0,3,5,1},
38  {5,1,4,7,0,3,6,2},
39  {4,0,5,6,1,2,7,3},
40  {3,1,2,7,0,5,6,4},
41  {2,0,3,6,1,4,7,5},
42  {1,0,3,5,2,4,7,6},
43  {0,1,2,4,3,5,6,7},
44  };
45 
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 };
55 
56  const float SliceClipper::v1[24] = {
57  0, 1, 4, 4,
58  1, 0, 1, 4,
59  0, 2, 5, 5,
60  2, 0, 2, 5,
61  0, 3, 6, 6,
62  3, 0, 3, 6 };
63 
64  const float SliceClipper::v2[24] = {
65  1, 4, 7, 7,
66  5, 1, 4, 7,
67  2, 5, 7, 7,
68  6, 2, 5, 7,
69  3, 6, 7, 7,
70  4, 3, 6, 7 };
71 
72 
73 void SliceClipper::updatePerFrameInfo( const eq::Matrix4d& modelviewM,
74  const double newSliceDistance,
75  const eq::Range& range
76 )
77 {
78  double zRs = -1+2.*range.start;
79  double zRe = -1+2.*range.end;
80 
81  //rendering parallelepipid's verteces
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);
87 
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);
92 
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] );
96 
97 
98  this->viewVec = eq::Vector4d( -modelviewM.array[ 2],
99  -modelviewM.array[ 6],
100  -modelviewM.array[10],
101  0.0 );
102 
103  viewVecf = eq::Vector3f( float( viewVec.x( )), float( viewVec.y( )),
104  float( viewVec.z( )));
105 
106  sliceDistance = newSliceDistance;
107 
108  frontIndex = 0;
109  float maxDist = float( viewVec.dot( vertices[0] ));
110  for( int i = 1; i < 8; i++ )
111  {
112  const float dist = float( viewVec.dot( vertices[i] ));
113  if ( dist > maxDist)
114  {
115  maxDist = dist;
116  frontIndex = i;
117  }
118  }
119 
120  planeStart = viewVec.dot( vertices[nSequence[frontIndex][0]] );
121  double dS = ceil( planeStart/sliceDistance );
122  planeStart = dS * sliceDistance;
123 }
124 
125 
126 eq::Vector3f SliceClipper::getPosition
127 (
128  const int vertexNum,
129  const int sliceNum
130 ) const
131 {
132  const float dPlaneDist = float( planeStart + sliceNum * sliceDistance );
133  float3 Position = float3( 0.0, 0.0, 0.0 );
134 
135  for( int e = 0; e < 4; e++ )
136  {
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])]);
141 
142  float3 vecV1( shaderVertices[vidx1 ],
143  shaderVertices[vidx1+1],
144  shaderVertices[vidx1+2] );
145 
146  float3 vecV2( shaderVertices[vidx2 ],
147  shaderVertices[vidx2+1],
148  shaderVertices[vidx2+2] );
149 
150  float3 vecStart = vecV1;
151  float3 vecDir = vecV2-vecV1;
152 
153  float denom = vecDir.dot( viewVecf );
154  float lambda = (denom != 0.0f) ?
155  (dPlaneDist - vecStart.dot(viewVecf))/denom : -1.0f;
156 
157  if(( lambda >= 0.0f ) && ( lambda <= 1.0f ))
158  {
159  Position = vecStart + vecDir * lambda;
160  break;
161  }
162  }
163  return Position;
164 }
165 
166 
167 }
168