27Vec3r SilhouetteGeomEngine::_Viewpoint =
Vec3r(0, 0, 0);
28real SilhouetteGeomEngine::_translation[3] = {0, 0, 0};
29real SilhouetteGeomEngine::_modelViewMatrix[4][4] = {
35real SilhouetteGeomEngine::_projectionMatrix[4][4] = {
41real SilhouetteGeomEngine::_transform[4][4] = {
47int SilhouetteGeomEngine::_viewport[4] = {1, 1, 1, 1};
48real SilhouetteGeomEngine::_Focal = 0.0;
50real SilhouetteGeomEngine::_glProjectionMatrix[4][4] = {
56real SilhouetteGeomEngine::_glModelViewMatrix[4][4] = {
62real SilhouetteGeomEngine::_znear = 0.0;
63real SilhouetteGeomEngine::_zfar = 100.0;
64bool SilhouetteGeomEngine::_isOrthographicProjection =
false;
66SilhouetteGeomEngine *SilhouetteGeomEngine::_pInstance =
nullptr;
69 const real iProjectionMatrix[4][4],
70 const int iViewport[4],
74 _translation[0] = iModelViewMatrix[3][0];
75 _translation[1] = iModelViewMatrix[3][1];
76 _translation[2] = iModelViewMatrix[3][2];
78 for (i = 0; i < 4; i++) {
79 for (j = 0; j < 4; j++) {
80 _modelViewMatrix[i][j] = iModelViewMatrix[j][i];
81 _glModelViewMatrix[i][j] = iModelViewMatrix[i][j];
85 for (i = 0; i < 4; i++) {
86 for (j = 0; j < 4; j++) {
87 _projectionMatrix[i][j] = iProjectionMatrix[j][i];
88 _glProjectionMatrix[i][j] = iProjectionMatrix[i][j];
92 for (i = 0; i < 4; i++) {
93 for (j = 0; j < 4; j++) {
95 for (
uint k = 0; k < 4; k++) {
96 _transform[i][j] += _projectionMatrix[i][k] * _modelViewMatrix[k][j];
101 for (i = 0; i < 4; i++) {
102 _viewport[i] = iViewport[i];
106 _isOrthographicProjection = (iProjectionMatrix[3][3] != 0.0);
117 memcpy(viewport, _viewport,
sizeof(
int[4]));
123 vector<SVertex *>::iterator sv, svend;
124 for (sv = ioVertices.begin(), svend = ioVertices.end(); sv != svend; sv++) {
126 (*sv)->point3D(), newPoint, _modelViewMatrix, _projectionMatrix, _viewport);
127 (*sv)->setPoint2D(newPoint);
135 ioVertex->
point3D(), newPoint, _modelViewMatrix, _projectionMatrix, _viewport);
141 if (_isOrthographicProjection) {
150 Vec3r Aw = (fe)->vertexA()->point3D();
151 Vec3r Bw = (fe)->vertexB()->point3D();
158 cout <<
"Ac " << Ac << endl;
159 cout <<
"Bc " << Bc << endl;
160 cout <<
"ABc " << ABc << endl;
163 Vec3r Ai = (fe)->vertexA()->point2D();
164 Vec3r Bi = (fe)->vertexB()->point2D();
165 Vec3r Ii = Ai + t * (Bi - Ai);
170 real m11 = _projectionMatrix[0][0];
171 real m13 = _projectionMatrix[0][2];
172 real m22 = _projectionMatrix[1][1];
173 real m23 = _projectionMatrix[1][2];
175 if (
fabs(ABc[0]) > 1.0e-6) {
176 alpha = ABc[2] / ABc[0];
177 beta = Ac[2] - alpha * Ac[0];
178 denom = alpha * (Ir[0] + m13) + m11;
179 if (
fabs(denom) < 1.0e-6) {
182 Ic[0] = -
beta * (Ir[0] + m13) / denom;
184 Ic[1] = -(Ir[1] + m23) * (alpha * Ic[0] +
beta) / m22;
185 Ic[2] = alpha * (Ic[0] - Ac[0]) + Ac[2];
187 T = (Ic[0] - Ac[0]) / ABc[0];
189 else if (
fabs(ABc[1]) > 1.0e-6) {
190 alpha = ABc[2] / ABc[1];
191 beta = Ac[2] - alpha * Ac[1];
192 denom = alpha * (Ir[1] + m23) + m22;
193 if (
fabs(denom) < 1.0e-6) {
196 Ic[1] = -
beta * (Ir[1] + m23) / denom;
198 Ic[0] = -(Ir[0] + m13) * (alpha * Ic[1] +
beta) / m11;
199 Ic[2] = alpha * (Ic[1] - Ac[1]) + Ac[2];
201 T = (Ic[1] - Ac[1]) / ABc[1];
205 bool x_coords, less_than;
206 if (
fabs(Bi[0] - Ai[0]) > 1.0e-6) {
208 less_than = Ai[0] < Bi[0];
212 less_than = Ai[1] < Bi[1];
217 real delta_x, delta_y, dist, dist_threshold = 1.0e-6;
218 int i, max_iters = 100;
219 for (i = 0; i < max_iters; i++) {
220 T = T_sta + 0.5 * (T_end - T_sta);
224 delta_x = Ii[0] - Pi[0];
225 delta_y = Ii[1] - Pi[1];
226 dist =
sqrt(delta_x * delta_x + delta_y * delta_y);
227 if (dist < dist_threshold) {
269 cout <<
"SilhouetteGeomEngine::ImageToWorldParameter(): #iters = " << i
270 <<
", dist = " << dist <<
"\n";
274 cout <<
"SilhouetteGeomEngine::ImageToWorldParameter(): reached to max_iters (dist = "
Various tools for geometry.
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
static Vec3r CameraToImage(const Vec3r &M)
static void setFrustum(real iZNear, real iZFar)
static void setTransform(const real iModelViewMatrix[4][4], const real iProjectionMatrix[4][4], const int iViewport[4], real iFocal)
static void ProjectSilhouette(std::vector< SVertex * > &ioVertices)
static real ImageToWorldParameter(FEdge *fe, real t)
static Vec3r WorldToImage(const Vec3r &M)
static void retrieveViewport(int viewport[4])
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)