15 #include "../geometry/GeomUtils.h"
23 Vec3r SilhouetteGeomEngine::_Viewpoint =
Vec3r(0, 0, 0);
24 real SilhouetteGeomEngine::_translation[3] = {0, 0, 0};
25 real SilhouetteGeomEngine::_modelViewMatrix[4][4] = {
31 real SilhouetteGeomEngine::_projectionMatrix[4][4] = {
37 real SilhouetteGeomEngine::_transform[4][4] = {
43 int SilhouetteGeomEngine::_viewport[4] = {1, 1, 1, 1};
44 real SilhouetteGeomEngine::_Focal = 0.0;
46 real SilhouetteGeomEngine::_glProjectionMatrix[4][4] = {
52 real SilhouetteGeomEngine::_glModelViewMatrix[4][4] = {
58 real SilhouetteGeomEngine::_znear = 0.0;
59 real SilhouetteGeomEngine::_zfar = 100.0;
60 bool SilhouetteGeomEngine::_isOrthographicProjection =
false;
62 SilhouetteGeomEngine *SilhouetteGeomEngine::_pInstance =
nullptr;
64 void SilhouetteGeomEngine::setTransform(
const real iModelViewMatrix[4][4],
65 const real iProjectionMatrix[4][4],
66 const int iViewport[4],
70 _translation[0] = iModelViewMatrix[3][0];
71 _translation[1] = iModelViewMatrix[3][1];
72 _translation[2] = iModelViewMatrix[3][2];
74 for (i = 0; i < 4; i++) {
75 for (j = 0; j < 4; j++) {
76 _modelViewMatrix[i][j] = iModelViewMatrix[j][i];
77 _glModelViewMatrix[i][j] = iModelViewMatrix[i][j];
81 for (i = 0; i < 4; i++) {
82 for (j = 0; j < 4; j++) {
83 _projectionMatrix[i][j] = iProjectionMatrix[j][i];
84 _glProjectionMatrix[i][j] = iProjectionMatrix[i][j];
88 for (i = 0; i < 4; i++) {
89 for (j = 0; j < 4; j++) {
91 for (
unsigned int k = 0; k < 4; k++) {
92 _transform[i][j] += _projectionMatrix[i][k] * _modelViewMatrix[k][j];
97 for (i = 0; i < 4; i++) {
98 _viewport[i] = iViewport[i];
102 _isOrthographicProjection = (iProjectionMatrix[3][3] != 0.0);
105 void SilhouetteGeomEngine::setFrustum(
real iZNear,
real iZFar)
111 void SilhouetteGeomEngine::retrieveViewport(
int viewport[4])
113 memcpy(viewport, _viewport,
sizeof(
int[4]));
116 void SilhouetteGeomEngine::ProjectSilhouette(vector<SVertex *> &ioVertices)
119 vector<SVertex *>::iterator sv, svend;
120 for (sv = ioVertices.begin(), svend = ioVertices.end(); sv != svend; sv++) {
122 (*sv)->point3D(), newPoint, _modelViewMatrix, _projectionMatrix, _viewport);
123 (*sv)->setPoint2D(newPoint);
127 void SilhouetteGeomEngine::ProjectSilhouette(
SVertex *ioVertex)
131 ioVertex->
point3D(), newPoint, _modelViewMatrix, _projectionMatrix, _viewport);
137 if (_isOrthographicProjection) {
146 Vec3r Aw = (fe)->vertexA()->point3D();
147 Vec3r Bw = (fe)->vertexB()->point3D();
154 cout <<
"Ac " << Ac << endl;
155 cout <<
"Bc " << Bc << endl;
156 cout <<
"ABc " << ABc << endl;
159 Vec3r Ai = (fe)->vertexA()->point2D();
160 Vec3r Bi = (fe)->vertexB()->point2D();
161 Vec3r Ii = Ai +
t * (Bi - Ai);
166 real m11 = _projectionMatrix[0][0];
167 real m13 = _projectionMatrix[0][2];
168 real m22 = _projectionMatrix[1][1];
169 real m23 = _projectionMatrix[1][2];
171 if (
fabs(ABc[0]) > 1.0e-6) {
172 alpha = ABc[2] / ABc[0];
173 beta = Ac[2] - alpha * Ac[0];
174 denom = alpha * (Ir[0] + m13) + m11;
175 if (
fabs(denom) < 1.0e-6) {
178 Ic[0] = -
beta * (Ir[0] + m13) / denom;
180 Ic[1] = -(Ir[1] + m23) * (alpha * Ic[0] +
beta) / m22;
181 Ic[2] = alpha * (Ic[0] - Ac[0]) + Ac[2];
183 T = (Ic[0] - Ac[0]) / ABc[0];
185 else if (
fabs(ABc[1]) > 1.0e-6) {
186 alpha = ABc[2] / ABc[1];
187 beta = Ac[2] - alpha * Ac[1];
188 denom = alpha * (Ir[1] + m23) + m22;
189 if (
fabs(denom) < 1.0e-6) {
192 Ic[1] = -
beta * (Ir[1] + m23) / denom;
194 Ic[0] = -(Ir[0] + m13) * (alpha * Ic[1] +
beta) / m11;
195 Ic[2] = alpha * (Ic[1] - Ac[1]) + Ac[2];
197 T = (Ic[1] - Ac[1]) / ABc[1];
201 bool x_coords, less_than;
202 if (
fabs(Bi[0] - Ai[0]) > 1.0e-6) {
204 less_than = Ai[0] < Bi[0];
208 less_than = Ai[1] < Bi[1];
213 real delta_x, delta_y, dist, dist_threshold = 1.0e-6;
214 int i, max_iters = 100;
215 for (i = 0; i < max_iters; i++) {
216 T = T_sta + 0.5 * (T_end - T_sta);
220 delta_x = Ii[0] - Pi[0];
221 delta_y = Ii[1] - Pi[1];
222 dist =
sqrt(delta_x * delta_x + delta_y * delta_y);
223 if (dist < dist_threshold) {
265 cout <<
"SilhouetteGeomEngine::ImageToWorldParameter(): #iters = " << i
266 <<
", dist = " << dist <<
"\n";
270 cout <<
"SilhouetteGeomEngine::ImageToWorldParameter(): reached to max_iters (dist = "
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
Class to perform all geometric operations dedicated to silhouette. That, for example,...
Classes to define a silhouette structure.
void setPoint2D(const Vec3r &iPoint2D)
const Vec3r & point3D() const
ccl_device_inline float2 fabs(const float2 &a)
void fromRetinaToImage(const Vec3r &p, Vec3r &q, const int viewport[4])
void fromWorldToImage(const Vec3r &p, Vec3r &q, const real model_view_matrix[4][4], const real projection_matrix[4][4], const int viewport[4])
void fromWorldToCamera(const Vec3r &p, Vec3r &q, const real model_view_matrix[4][4])
void fromCameraToRetina(const Vec3r &p, Vec3r &q, const real projection_matrix[4][4])
void fromImageToRetina(const Vec3r &p, Vec3r &q, const int viewport[4])
VecMat::Vec3< real > Vec3r
ccl_device_inline float beta(float x, float y)