Create openMVS.build

This commit is contained in:
hesuicong committed 2025-09-26 10:13:00 +08:00
commit 365aa390ba
1856 files changed
+839085

No files matched your search

@@ -0,0 +1,10 @@
TARGET = camerashot_test
INCLUDEPATH += . ../../..
CONFIG += console stl
TEMPLATE = app
SOURCES += camerashot_test.cpp
win32: CONFIG += NOMINMAX
# Mac specific Config required to avoid to make application bundles
CONFIG -= app_bundle
@@ -0,0 +1,597 @@
// STD headers
#include <iostream>
#include <assert.h>
// VCG headers
#include <vcg/math/camera.h>
#include <vcg/math/shot.h>
static double precision = 0.000000001; // 1e-9
double dist2(vcg::Point2d p1, vcg::Point2d p2)
{
double d = sqrt((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]));
return d;
}
double dist3(vcg::Point3d p1, vcg::Point3d p2)
{
double d = sqrt((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]) + (p1[2] - p2[2]) * (p1[2] - p2[2]));
return d;
}
double checkIdentity(vcg::Matrix44d M)
{
double d;
d = (M.ElementAt(0,0) - 1.0) * (M.ElementAt(0,0) - 1.0) + M.ElementAt(0,1) * M.ElementAt(0,1) + M.ElementAt(0,2) * M.ElementAt(0,2) + M.ElementAt(0,3) * M.ElementAt(0,3);
d += M.ElementAt(1,0) * M.ElementAt(1,0) + (M.ElementAt(1,1) - 1.0) * (M.ElementAt(1,1) - 1.0) + M.ElementAt(1,2) * M.ElementAt(1,2) + M.ElementAt(1,3) * M.ElementAt(1,3);
d += M.ElementAt(2,0) * M.ElementAt(2,0) + M.ElementAt(2,1) * M.ElementAt(2,1) + (M.ElementAt(2,2) - 1.0) * (M.ElementAt(2,2) - 1.0) + M.ElementAt(2,3) * M.ElementAt(2,3);
d += M.ElementAt(3,0) * M.ElementAt(3,0) + M.ElementAt(3,1) * M.ElementAt(3,1) + M.ElementAt(3,2) * M.ElementAt(3,2) + (M.ElementAt(3,3) - 1.0) * (M.ElementAt(3,3) - 1.0);
return d;
}
// TEST1 - PROJECT A 3D POINT IN WORLD COORDINATE ON THE IMAGE PLANE
///////////////////////////////////////////////////////////////////////////////
bool test1(vcg::Shotd shot1, vcg::Shotd shot2, vcg::Point3d p1, vcg::Point3d p2)
{
vcg::Point2d p1proj, p2proj;
p1proj = shot1.Project(p1);
p2proj = shot2.Project(p2);
vcg::Point2d p1test(633.58101456110933, 327.22860336234237);
vcg::Point2d p2test(289.02943695191425, 315.42715619973069);
if (dist2(p1proj,p1test) > precision)
return false;
if (dist2(p2proj,p2test) > precision)
return false;
return true;
}
// TEST 2 - PROJECTION AND UNPROJECTION
///////////////////////////////////////////////////////////////////////////////
bool test2(vcg::Shotd shot1, vcg::Shotd shot2, vcg::Point3d p1, vcg::Point3d p2)
{
vcg::Point2d p1proj, p2proj;
p1proj = shot1.Project(p1);
p2proj = shot2.Project(p2);
vcg::Point3d p1unproj, p2unproj;
vcg::Point3d pcam1, pcam2;
pcam1 = shot1.ConvertWorldToCameraCoordinates(p1);
p1unproj = shot1.UnProject(p1proj, pcam1[2]);
pcam2 = shot2.ConvertWorldToCameraCoordinates(p2);
p2unproj = shot2.UnProject(p2proj, pcam2[2]);
if (dist3(p1, p1unproj) > precision)
return false;
if (dist3(p2, p2unproj) > precision)
return false;
return true;
}
// TEST 3 - DEPTH COMPUTATION
///////////////////////////////////////////////////////////////////////////////
bool test3(vcg::Shotd shot1, vcg::Shotd shot2, vcg::Point3d p1, vcg::Point3d p2)
{
vcg::Point2d p1proj, p2proj;
p1proj = shot1.Project(p1);
p2proj = shot2.Project(p2);
vcg::Point3d p1unproj, p2unproj;
double depth1 = shot1.Depth(p1);
double depth2 = shot2.Depth(p2);
p1unproj = shot1.UnProject(p1proj, depth1);
p2unproj = shot2.UnProject(p2proj, depth2);
if (dist3(p1, p1unproj) > precision)
return false;
if (dist3(p2, p2unproj) > precision)
return false;
return true;
}
// TEST 4 - CAMERA CONVERSION - CONVERT FOCAL IN PIXELS IN FOCAL IN MM
///////////////////////////////////////////////////////////////////////////////
bool test4(vcg::Shotd shot, vcg::Point3d p1)
{
vcg::Shotd shotpx = shot;
// we assume focal is in pixels
shotpx.Intrinsics.FocalMm = 1028.5949393128985805389837482;
shotpx.Intrinsics.PixelSizeMm[0] = 1.0;
shotpx.Intrinsics.PixelSizeMm[1] = 1.0;
vcg::Point2d pproj;
pproj = shotpx.Project(p1);
vcg::Point2d p1proj;
p1proj = shot.Project(p1);
if(dist2(pproj, p1proj) > precision)
return false;
// CONVERSION - (ccd is assumed to be 35mm width)
shot.ConvertFocalToMM();
p1proj = shotpx.Project(p1);
if (dist2(pproj, p1proj) > precision)
return false;
return true;
}
// TEST 5 - CAMERA-SHOT MODIFICATION - CHANGE SCALE FACTOR OF THE WORLD
///////////////////////////////////////////////////////////////////////////////
bool test5(vcg::Shotd shot, vcg::Point3d p1, vcg::Point3d p2)
{
vcg::Point2d p1projPX, p2projPX;
p1projPX = shot.Project(p1);
p2projPX = shot.Project(p2);
vcg::Point2d p1proj, p2proj;
p1proj = shot.Intrinsics.ViewportPxToLocal(p1projPX);
p2proj = shot.Intrinsics.ViewportPxToLocal(p2projPX);
vcg::Point2d diff;
double distance_before_world_scaling;
diff = (p2proj-p1proj);
distance_before_world_scaling = diff.Norm();
// WORLD SCALING
double scalefactor = 20.0;
// adjust World 3D points
p1 *= scalefactor;
p2 *= scalefactor;
shot.RescalingWorld(scalefactor);
p1projPX = shot.Project(p1);
p2projPX = shot.Project(p2);
p1proj = shot.Intrinsics.ViewportPxToLocal(p1projPX);
p2proj = shot.Intrinsics.ViewportPxToLocal(p2projPX);
double distance_after_world_scaling;
diff = (p2proj - p1proj);
distance_after_world_scaling = diff.Norm();
if (vcg::math::Abs(distance_before_world_scaling - (distance_after_world_scaling / scalefactor)) > precision)
return false;
return true;
}
// TEST 6 - WORLD-TO-EXTRINSICS AND EXTRINSICS-TO-WORLD TRANSFORMATIONS
bool test6(vcg::Shotd shot1, vcg::Shotd shot2, vcg::Point3d p1, vcg::Point3d p2)
{
vcg::Matrix44d WtoE1 = shot1.GetWorldToExtrinsicsMatrix();
vcg::Matrix44d WtoE2 = shot2.GetWorldToExtrinsicsMatrix();
vcg::Matrix44d EtoW1 = shot1.GetExtrinsicsToWorldMatrix();
vcg::Matrix44d EtoW2 = shot2.GetExtrinsicsToWorldMatrix();
vcg::Matrix44d I1 = WtoE1 * EtoW1;
vcg::Matrix44d I2 = WtoE2 * EtoW2;
vcg::Matrix44d I3 = EtoW1 * WtoE1;
vcg::Matrix44d I4 = EtoW2 * WtoE2;
if (checkIdentity(I1) > precision)
return false;
if (checkIdentity(I2) > precision)
return false;
if (checkIdentity(I3) > precision)
return false;
if (checkIdentity(I4) > precision)
return false;
vcg::Point3d axisX(1.0, 0.0, 0.0);
vcg::Point3d axisY(0.0, 1.0, 0.0);
vcg::Point3d axisZ(0.0, 0.0, 1.0);
vcg::Point3d vx = EtoW1 * axisX;
vcg::Point3d vy = EtoW1 * axisY;
vcg::Point3d vz = EtoW1 * axisZ;
if (dist3(vx, shot1.Extrinsics.Tra() + shot1.Extrinsics.Rot().GetRow3(0)) > precision)
return false;
if (dist3(vy, shot1.Extrinsics.Tra() + shot1.Extrinsics.Rot().GetRow3(1)) > precision)
return false;
if (dist3(vz, shot1.Extrinsics.Tra() + shot1.Extrinsics.Rot().GetRow3(2)) > precision)
return false;
return true;
}
// TEST 7 - SHOT MODIFICATION - ROTATION + TRANSLATION
///////////////////////////////////////////////////////////////////////////////
bool test7(vcg::Shotd shot1, vcg::Point3d p1, vcg::Point3d p2)
{
// store data
vcg::Matrix44d Rorig = shot1.Extrinsics.Rot();
vcg::Point3d Torig = shot1.Extrinsics.Tra();
// pure translation
vcg::Matrix44d T;
T.SetIdentity();
T.ElementAt(0,3) = 10.0;
T.ElementAt(1,3) = 10.0;
T.ElementAt(2,3) = 10.0;
T.ElementAt(3,3) = 1.0;
vcg::Point2d p1proj = shot1.Project(p1);
vcg::Point3d tr(T.ElementAt(0,3), T.ElementAt(1,3), T.ElementAt(2,3));
vcg::Point3d pt = p1 + tr;
shot1.ApplyRigidTransformation(T);
vcg::Point2d ptproj = shot1.Project(pt);
if (dist2(p1proj, ptproj) > precision)
return false;
// restore the original reference frame to test another transformation
shot1.Extrinsics.SetTra(Torig);
shot1.Extrinsics.SetRot(Rorig);
// pure rotation
vcg::Matrix44d R;
R.SetZero();
R.ElementAt(0,2) = 1.0;
R.ElementAt(1,1) = 1.0;
R.ElementAt(2,0) = -1.0;
R.ElementAt(3,3) = 1.0;
vcg::Point3d pr = R * p1;
shot1.ApplyRigidTransformation(R);
vcg::Point2d prproj = shot1.Project(pr);
if (dist2(p1proj, prproj) > precision)
return false;
// restore the original reference frame to test another transformation
shot1.Extrinsics.SetTra(Torig);
shot1.Extrinsics.SetRot(Rorig);
// roto-translation
vcg::Matrix44d RT = T * R;
vcg::Point3d prt = R * p1 + tr;
shot1.ApplyRigidTransformation(RT);
vcg::Point2d prtproj = shot1.Project(prt);
if (dist2(p1proj, prtproj) > precision)
return false;
return true;
}
// TEST 8 - SHOT MODIFICATION - ROTATION + TRANSLATION
///////////////////////////////////////////////////////////////////////////////
bool test8(vcg::Shotd shot1, vcg::Shotd shot2, vcg::Point3d p1, vcg::Point3d p2)
{
// put shot1 reference frame into the origin of the World coordinates system
vcg::Matrix44d M = shot1.GetWorldToExtrinsicsMatrix();
// NOTE: The roto-translation which maps the point p in World coordinates to the Shot frame
// applied to the frame bring it in the world frame.
shot1.ApplyRigidTransformation(M);
// then, put in the shot2 reference frame
M = shot2.GetExtrinsicsToWorldMatrix();
shot1.ApplyRigidTransformation(M);
// test..
vcg::Point2d p1proj1, p2proj1, p1proj2, p2proj2;
p1proj1 = shot1.Project(p1);
p1proj2 = shot2.Project(p1);
p2proj1 = shot1.Project(p2);
p2proj2 = shot2.Project(p2);
if (dist2(p1proj1, p1proj2) > precision)
return false;
if (dist2(p2proj1, p2proj2) > precision)
return false;
return true;
}
// TEST 9 - SHOT MODIFICATION - ROTATION + TRANSLATION
///////////////////////////////////////////////////////////////////////////////
bool test9(vcg::Shotd shot1, vcg::Shotd shot2, vcg::Point3d p1, vcg::Point3d p2)
{
vcg::Matrix44d M1 = shot1.GetExtrinsicsToWorldMatrix();
vcg::Matrix44d M2 = shot2.GetWorldToExtrinsicsMatrix();
vcg::Matrix44d M;
M = M2 * M1; // is the roto-translation that maps a point in the frame of Shot1 in a point in the frame of Shot2
// BUT M2 brings the frame of Shot2 in the World system and M1 brings the World system in the Shot1 reference frame
// HENCE the combined roto-translation which maps the frame of Shot2 in the frame of Shot2 is M1 * M2 (!!!)
vcg::Matrix44d Mframe = M1 * M2;
// apply it..
shot2.ApplyRigidTransformation(Mframe);
// and test it..
vcg::Point2d p1proj1, p2proj1, p1proj2, p2proj2;
p1proj1 = shot1.Project(p1);
p1proj2 = shot2.Project(p1);
p2proj1 = shot1.Project(p2);
p2proj2 = shot2.Project(p2);
if (dist2(p1proj1, p1proj2) > precision)
return false;
if (dist2(p2proj1, p2proj2) > precision)
return false;
return true;
}
// TEST 10 - SHOT MODIFICATION - SIMILARITY
///////////////////////////////////////////////////////////////////////////////
bool test10(vcg::Shotd shot1, vcg::Shotd shot2, vcg::Point3d p1, vcg::Point3d p2)
{
vcg::Point2d p1proj = shot1.Project(p1);
// store data
vcg::Matrix44d Rorig = shot1.Extrinsics.Rot();
vcg::Point3d Torig = shot1.Extrinsics.Tra();
// pure translation
vcg::Matrix44d T;
T.SetIdentity();
T.ElementAt(0,3) = 10.0;
T.ElementAt(1,3) = 10.0;
T.ElementAt(2,3) = 10.0;
T.ElementAt(3,3) = 1.0;
vcg::Point3d tr(T.ElementAt(0,3), T.ElementAt(1,3), T.ElementAt(2,3));
// pure rotation
vcg::Matrix44d R;
R.SetZero();
R.ElementAt(0,2) = 1.0;
R.ElementAt(1,1) = 1.0;
R.ElementAt(2,0) = -1.0;
R.ElementAt(3,3) = 1.0;
// scaling
vcg::Matrix44d S;
double scale = 10.0;
S.SetIdentity();
S *= scale;
S.ElementAt(3,3) = 1.0;
vcg::Point3d psim = R * S * p1 + tr;
vcg::Matrix44d SRT = T * R * S;
shot1.ApplySimilarity(SRT);
vcg::Point2d psimproj = shot1.Project(psim);
if (dist2(p1proj, psimproj) > precision)
return false;
// restore the original reference frame to test another transformation
shot1.Extrinsics.SetTra(Torig);
shot1.Extrinsics.SetRot(Rorig);
vcg::Similarityd sm;
double pihalf = 3.1415926535897932384626433832795 / 2.0;
sm.SetRotate(pihalf, vcg::Point3d(0.0,1.0,0.0));
sm.sca = scale;
sm.tra = tr;
shot1.ApplySimilarity(sm);
psimproj = shot1.Project(psim);
if (dist2(p1proj, psimproj) > precision)
return false;
return true;
}
int main()
{
vcg::Point3d p1(20.0, 25.0, 10.0);
vcg::Point3d p2(-6.0, 25.0, 50.0);
vcg::Shotd shot1;
vcg::Shotd shot2;
// Initialize camera 1 (C1)
shot1.Intrinsics.cameraType = vcg::Camera<double>::PERSPECTIVE;
shot1.Intrinsics.FocalMm = 30.0;
shot1.Intrinsics.CenterPx[0] = 600.0; shot1.Intrinsics.CenterPx[1] = 400.0;
shot1.Intrinsics.ViewportPx[0] = 1200; shot1.Intrinsics.ViewportPx[1] = 800;
shot1.Intrinsics.PixelSizeMm[0] = 0.029166; shot1.Intrinsics.PixelSizeMm[1] = 0.029166;
// no distorion is assumed (!)
shot1.Intrinsics.DistorCenterPx[0] = shot1.Intrinsics.DistorCenterPx[1] = 0.0;
shot1.Intrinsics.k[0] = 0.0; shot1.Intrinsics.k[1] = 0.0; shot1.Intrinsics.k[2] = 0.0; shot1.Intrinsics.k[3] = 0.0;
vcg::Matrix44d R1; // -10 degree around Y axis
double deg2rad = 0.01745329251994329576923690768489;
R1.ElementAt(0,0) = vcg::math::Cos(-10.0*deg2rad);
R1.ElementAt(0,1) = 0.0;
R1.ElementAt(0,2) = vcg::math::Sin(-10.0*deg2rad);
R1.ElementAt(0,3) = 0.0;
R1.ElementAt(1,0) = 0.0;
R1.ElementAt(1,1) = 1.0;
R1.ElementAt(1,2) = 0.0;
R1.ElementAt(1,3) = 0.0;
R1.ElementAt(2,0) = -vcg::math::Sin(-10.0*deg2rad);
R1.ElementAt(2,1) = 0.0;
R1.ElementAt(2,2) = vcg::math::Cos(-10.0*deg2rad);
R1.ElementAt(2,3) = 0.0;
R1.ElementAt(3,0) = 0.0;
R1.ElementAt(3,1) = 0.0;
R1.ElementAt(3,2) = 0.0;
R1.ElementAt(3,3) = 1.0;
vcg::Point3d T1(30.0, 30.0, 80.0);
shot1.Extrinsics.SetTra(T1);
shot1.Extrinsics.SetRot(R1);
// Initialize camera 2 (C2)
shot2.Intrinsics.cameraType = vcg::Camera<double>::PERSPECTIVE;
shot2.Intrinsics.FocalMm = 30.0;
shot2.Intrinsics.CenterPx[0] = 600.0; shot2.Intrinsics.CenterPx[1] = 400.0;
shot2.Intrinsics.ViewportPx[0] = 1200; shot2.Intrinsics.ViewportPx[1] = 800;
shot2.Intrinsics.PixelSizeMm[0] = 0.029166; shot2.Intrinsics.PixelSizeMm[1] = 0.029166;
// no distortion is assumed (!)
shot2.Intrinsics.DistorCenterPx[0] = shot2.Intrinsics.DistorCenterPx[1] = 0.0;
shot2.Intrinsics.k[0] = 0.0; shot2.Intrinsics.k[1] = 0.0; shot2.Intrinsics.k[2] = 0.0; shot2.Intrinsics.k[3] = 0.0;
vcg::Matrix44d R2; // 18 degree around Y axis (+ 180 degree for the correct orientation of the camera)
R2.ElementAt(0,0) = vcg::math::Cos(-45.0*deg2rad);
R2.ElementAt(0,1) = 0.0;
R2.ElementAt(0,2) = vcg::math::Sin(-45.0*deg2rad);
R2.ElementAt(0,3) = 0.0;
R2.ElementAt(1,0) = 0.0;
R2.ElementAt(1,1) = 1.0;
R2.ElementAt(1,2) = 0.0;
R2.ElementAt(1,3) = 0.0;
R2.ElementAt(2,0) = -vcg::math::Sin(-45.0*deg2rad);
R2.ElementAt(2,1) = 0.0;
R2.ElementAt(2,2) = vcg::math::Cos(-45.0*deg2rad);
R2.ElementAt(2,3) = 0.0;
R2.ElementAt(3,0) = 0.0;
R2.ElementAt(3,1) = 0.0;
R2.ElementAt(3,2) = 0.0;
R2.ElementAt(3,3) = 1.0;
vcg::Point3d T2(50.0, 30.0, 80.0);
shot2.Extrinsics.SetTra(T2);
shot2.Extrinsics.SetRot(R2);
// TEST 1 - project a 3D point in World coordinates on the image plane
if (test1(shot1, shot2, p1, p2))
{
std::cout << "TEST 1 (projection) - PASSED(!)" << std::endl;
}
else
std::cout << "TEST 1 (projection) - FAILED(!)" << std::endl;
// TEST 2 - projection and unprojection
if (test2(shot1, shot2, p1, p2))
{
std::cout << "TEST 2 (unprojection) - PASSED(!)" << std::endl;
}
else
{
std::cout << "TEST 2 (unprojection) - FAILED(!)" << std::endl;
}
// TEST 3 - DEPTH COMPUTATION
if (test3(shot1, shot2, p1, p2))
{
std::cout << "TEST 3 (depth computation) - PASSED(!)" << std::endl;
}
else
{
std::cout << "TEST 3 (depth computation) - FAILED(!)" << std::endl;
}
// TEST 4 - CAMERA CONVERSION - CONVERT FOCAL IN PIXELS IN FOCAL IN MM
if (test4(shot1, p1))
{
std::cout << "TEST 4 (focal in px to focal in mm) - PASSED(!)" << std::endl;
}
else
{
std::cout << "TEST 4 (focal in px to focal in mm) - FAILED(!)" << std::endl;
}
// TEST 5 - CAMERA-SHOT MODIFICATION - CHANGE SCALE FACTOR OF THE WORLD
if (test5(shot1, p1, p2))
{
std::cout << "TEST 5 (scaling the World) - PASSED(!)" << std::endl;
}
else
{
std::cout << "TEST 5 (scaling the World) - FAILED(!)" << std::endl;
}
// TEST 6 - WORLD-TO-EXTRINSICS AND EXTRINSICS-TO-WORLD TRANSFORMATIONS
if (test6(shot1, shot2, p1, p2))
{
std::cout << "TEST 6 (World-to-Extrinsics and Extrinsics-to-World) - PASSED(!)" << std::endl;
}
else
{
std::cout << "TEST 6 (World-to-Extrinsics and Extrinsics-to-World) - FAILE(!)" << std::endl;
}
// TEST 7 - SHOT MODIFICATION - ROTO-TRANSLATION OF THE SHOT COORDINATES SYSTEM
if (test7(shot1, p1, p2))
{
std::cout << "TEST 7 (roto-translation of the Shot coordinates system) - PASSED(!)" << std::endl;
}
else
{
std::cout << "TEST 7 (roto-translation of the Shot coordinates system) - FAILED(!)" << std::endl;
}
// TEST 7 - SHOT MODIFICATION - ROTO-TRANSLATION OF THE SHOT COORDINATES SYSTEM
if (test8(shot1, shot2, p1, p2))
{
std::cout << "TEST 8 (roto-translation of the Shot coordinates system) - PASSED(!)" << std::endl;
}
else
{
std::cout << "TEST 8 (roto-translation of the Shot coordinates system) - FAILED(!)" << std::endl;
}
// TEST 9 - SHOT MODIFICATION - ROTO-TRANSLATION OF THE SHOT COORDINATES SYSTEM
if (test9(shot1, shot2, p1, p2))
{
std::cout << "TEST 9 (roto-translation of the Shot coordinates system) - PASSED(!)" << std::endl;
}
else
{
std::cout << "TEST 9 (roto-translation of the Shot coordinates system) - FAILED(!)" << std::endl;
}
// TEST 10 - SHOT MODIFICATION - SIMILARITY TRANSFORMATION
if (test10(shot1, shot2, p1, p2))
{
std::cout << "TEST 10 (similarity transform of the Shot coordinates system) - PASSED(!)" << std::endl;
}
else
{
std::cout << "TEST 10 (similarity transform of the Shot coordinates system) - FAILED(!)" << std::endl;
}
return 0;
}
+157
View File
@@ -0,0 +1,157 @@
#include <iostream>
using namespace std;
#include <vcg/math/quaternion.h>
#include <vcg/math/matrix33.h>
using namespace vcg;
ostream &operator<<(ostream &o, Point3f &q) {
o.precision(6) ;
o.setf( ios::fixed, ios::floatfield ) ;
o << "[" << q[0] << " " << q[1] << " " << q[2] << "]";
return o;
}
ostream &operator<<(ostream &o, Quaternionf &q) {
o.precision(6) ;
o.setf( ios::fixed, ios::floatfield ) ;
o << "[" << q[0] << " " << q[1] << " " << q[2] << " " << q[3] << "]";
return o;
}
ostream &operator<<(ostream &o, Matrix33f &m) {
o.precision(6) ;
o.setf( ios::fixed, ios::floatfield ) ;
for(int i = 0; i < 3; i++) {
o << "[";
for(int j = 0; j < 3; j++) {
o << m[i][j] << " ";
}
o << "] ";
}
return o;
}
ostream &operator<<(ostream &o, Matrix44f &m) {
o.precision(6) ;
o.setf( ios::fixed, ios::floatfield ) ;
for(int i = 0; i < 4; i++) {
o << "[";
for(int j = 0; j < 4; j++) {
o << m[i][j] << " ";
}
o << "] ";
}
return o;
}
bool verify(Quaternionf &q){
cout << "Quaternion: " << q << endl;
Matrix33f m;
q.ToMatrix(m);
cout << "To Matrix: " << m << endl;
cout << "Row norms: " << m.GetRow(0).Norm() << " "
<< m.GetRow(1).Norm() << " "
<< m.GetRow(2).Norm() << endl;
Point3f p(3, 4, 5);
Point3f qp = q.Rotate(p);
Point3f mp = m*p;
cout << "Rotating p: " << p << endl;
cout << "q*p = " << qp << " m*p: " << mp << endl;
q.FromMatrix(m);
cout << "Back to: " << q << endl << endl;
return true;
}
bool verify(Matrix33f &m) {
cout << "Matrix: " << m << endl;
cout << "Det: " << m.Determinant() << endl;
cout << "Row norms: " << m.GetRow(0).Norm() << " "
<< m.GetRow(1).Norm() << " "
<< m.GetRow(2).Norm() << endl;
cout << "Column norms: " << m.GetColumn(0).Norm() << " "
<< m.GetColumn(1).Norm() << " "
<< m.GetColumn(2).Norm() << endl;
Matrix33f im = m.transpose() * m;
im = im*m;
cout << "Check ortonormality: " << im << endl;
Quaternionf q;
q.FromMatrix(m);
cout << "To Quaternion: " << q << endl;
float alpha = 2*acos(q[0]);
Point3f axis(q[1], q[2], q[3]);
cout << "Norm: " << axis.SquaredNorm() + q[0]*q[0] << endl;
axis.Normalize();
cout << "angle: " << 2*acos(q[0]) << " Axis: " << axis << endl;
Point3f p(3, 4, 5);
Point3f qp = q.Rotate(p);
Point3f mp = m*p;
cout << "Rotating p: " << p << endl;
cout << "q*p = " << qp << " m*p: " << mp << endl;
q.ToMatrix(m);
cout << "Back to: " << m << endl<< endl;
}
int main() {
Quaternionf q(1, 0, 0, 0); /*identity*/
// cout << "Verify identity: " << endl;
verify(q);
q.FromAxis(M_PI/2, Point3f(0, 0, 1));
// cout << "Verify 90 degrees\n";
verify(q);
q.FromAxis(M_PI/4, Point3f(0, 1, 1));
// cout << "Verify 45 degrees\n";
verify(q);
Matrix33f m;
m[0][0] = 0.70145; m[0][1] = 0.372035; m[0][2] = 0.607913;
m[1][0] = -0.628023; m[1][1] = 0.725922; m[1][2] = 0.2804;
m[2][0] = -0.336978; m[2][1] = -0.57847; m[2][2] = 0.742845;
cout << "verify matrix: " << endl;
verify(m);
verify(m);
q.FromAxis(0.7, Point3f(-0.20, -0.42, -0.83));
cout << "verify from axis: " << endl;
verify(q);
// Quaternionf q(0.648947, -0.114828, -0.104375, -0.385262);
Quaternionf iq= Inverse(q);
//Matrix33f m;
cout << "matrix: " << m << endl;
Point3f p(3, 4, 5);
//test this matrix:
cout << "norms: " << m.GetRow(0).Norm() << " " << m.GetRow(1).Norm() << " " << m.GetRow(2).Norm() << endl;
q.FromMatrix(m);
q.ToMatrix(m);
cout << "quaternion: " << q[0] << " " << q[1] << " " << q[2] << " " << q[3] <<endl;
cout << "matrix: " << endl;
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
cout << m[i][j] << " ";
}
cout << endl;
}
cout << endl;
cout << "Point: " << p[0] << " " << p[1] << " " << p[2] << endl;
Point3f r = q.Rotate(p);
cout << "Rotated by q: " << r[0] << " " << r[1] << " " << r[2] << endl;
r = m*p;
cout << "Rotated by m: " << r[0] << " " << r[1] << " " << r[2] << endl;
q.FromMatrix(m);
cout << "quaternion: " << q[0] << " " << q[1] << " " << q[2] << " " << q[3] <<endl;
return 0;
}
+32
View File
@@ -0,0 +1,32 @@
#include <simplex\vertex\with\a.h>
#include <simplex\tetrahedron\with\avq.h>
#include <simplex\face\with\fa.h>
#include <complex\tetramesh\base.h>
#include <complex\tetramesh\update\topology.h>
#include <complex\tetramesh\update\allocate.h>
#include<vector>
#include<complex\tetramesh\update\triconvert.h>
#include<complex\trimesh\base.h>
using namespace vcg;
using namespace tetra;
using namespace tri;
#include<apps\test\tetramesh\test\myclasses.h>
int main( int argc, char **argv )
{
MyMesh tm=MyMesh();
UpdateTopology<vector<MyVertex>,vector<MyTetrahedron> > ut= UpdateTopology<vector<MyVertex>,vector<MyTetrahedron> >();
Allocator<MyMesh> All= Allocator<MyMesh>();
vector<MyVertex **> local_var=vector<MyVertex **>();
char* filename="sphere.ts";
tm.LoadTs(filename,1);
ut.TTTopology(tm.vert,tm.tetra);
ut.TestTTTopology(tm.vert,tm.tetra);
ut.VTTopology(tm.vert,tm.tetra);
All.AddVertices(tm,10,local_var);
All.AddVertices(tm,10);
ut.TestTTTopology(tm.vert,tm.tetra);
MyTriMesh mesh;
TriConverter <MyMesh,MyTriMesh>tric=TriConverter<MyMesh,MyTriMesh>();
tric.Convert(tm,mesh);
}
Binary file not shown.
+21
View File
@@ -0,0 +1,21 @@
Microsoft Visual Studio Solution File, Format Version 7.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test.vcproj", "{27987C13-6147-48FE-AA21-B2175451AA13}"
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
ConfigName.0 = Debug
ConfigName.1 = Release
EndGlobalSection
GlobalSection(ProjectDependencies) = postSolution
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{27987C13-6147-48FE-AA21-B2175451AA13}.Debug.ActiveCfg = Debug|Win32
{27987C13-6147-48FE-AA21-B2175451AA13}.Debug.Build.0 = Debug|Win32
{27987C13-6147-48FE-AA21-B2175451AA13}.Release.ActiveCfg = Release|Win32
{27987C13-6147-48FE-AA21-B2175451AA13}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal
Binary file not shown.
+142
View File
@@ -0,0 +1,142 @@
<?xml version="1.0" encoding = "Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.00"
Name="test"
ProjectGUID="{27987C13-6147-48FE-AA21-B2175451AA13}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="d:\sf\vcg\;d:\sf;d:\sf\vcg\simplex;"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="5"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/test.exe"
LinkIncremental="2"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/test.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
OmitFramePointers="TRUE"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
StringPooling="TRUE"
RuntimeLibrary="4"
EnableFunctionLevelLinking="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/test.exe"
LinkIncremental="1"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
</Configuration>
</Configurations>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
<File
RelativePath="test.cpp">
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc">
<File
RelativePath="..\..\..\..\vcg\complex\tetramesh\update\allocate.h">
</File>
<File
RelativePath="..\..\..\..\vcg\simplex\tetrahedron\base.h">
</File>
<File
RelativePath="..\..\..\..\vcg\complex\tetramesh\base.h">
</File>
<File
RelativePath="myclasses.h">
</File>
<File
RelativePath="..\..\..\..\vcg\space\tetra4.h">
</File>
<File
RelativePath="..\..\..\..\vcg\complex\tetramesh\update\topology.h">
</File>
<File
RelativePath="..\..\..\..\vcg\complex\tetramesh\update\triconvert.h">
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
+166
View File
@@ -0,0 +1,166 @@
#include <iostream>
using namespace std;
#ifdef _WIN32
#include<windows.h>
#endif
#include <SDL/SDL.h>
//#include <GL/glew.h>
#include <wrap/gui/trackball.h>
#include <GL/glut.h>
using namespace vcg;
bool fullscreen = false;
//int width =1024;
//int height = 768;
int width = 800;
int height = 600;
SDL_Surface *screen = NULL;
bool init() {
if(SDL_Init(SDL_INIT_VIDEO) != 0) {
return false;
}
const SDL_VideoInfo *info = SDL_GetVideoInfo();
int bpp = info->vfmt->BitsPerPixel;
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
int flags = SDL_OPENGL;
if(fullscreen)
flags |= SDL_FULLSCREEN;
screen = SDL_SetVideoMode(width, height, bpp, flags);
if(!screen) {
return false;
}
SDL_WM_SetIcon(SDL_LoadBMP("inspector.bmp"), NULL);
SDL_WM_SetCaption(" Inspector", "Inspector");
glDisable(GL_DITHER);
glShadeModel(GL_SMOOTH);
glHint( GL_FOG_HINT, GL_NICEST );
glEnable(GL_DEPTH_TEST);
glDepthFunc( GL_LEQUAL );
glDisable(GL_LIGHTING);
return true;
}
int main(int argc, unsigned short **argv) {
if(!init()) return -1;
glewInit();
Trackball trackball;
int quit = 0;
int x, y;
SDL_Event event;
while( !quit ) {
while( SDL_PollEvent( &event ) ){
switch( event.type ) {
case SDL_QUIT: quit = 1; break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym) {
case SDLK_RSHIFT:
case SDLK_LSHIFT:
trackball.ButtonDown(Trackball::KEY_SHIFT);
break;
case SDLK_RCTRL:
case SDLK_LCTRL:
trackball.ButtonDown(Trackball::KEY_CTRL);
break;
case SDLK_RALT:
case SDLK_LALT:
trackball.ButtonDown(Trackball::KEY_ALT);
break;
}
break;
case SDL_KEYUP:
switch(event.key.keysym.sym) {
case SDLK_q: exit(0); break;
case SDLK_RSHIFT:
case SDLK_LSHIFT:
trackball.ButtonUp(Trackball::KEY_SHIFT);
break;
case SDLK_RCTRL:
case SDLK_LCTRL:
trackball.ButtonUp(Trackball::KEY_CTRL);
break;
case SDLK_RALT:
case SDLK_LALT:
trackball.ButtonUp(Trackball::KEY_ALT);
break;
}
break;
case SDL_MOUSEBUTTONDOWN:
x = event.button.x;
y = height - event.button.y;
trackball.MouseDown(x, y, Trackball::BUTTON_LEFT);
break;
case SDL_MOUSEBUTTONUP:
x = event.button.x;
y = height - event.button.y;
trackball.MouseUp(x, y, Trackball::BUTTON_LEFT);
break;
case SDL_MOUSEMOTION:
while(SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_MOUSEMOTIONMASK));
x = event.motion.x;
y = height - event.motion.y;
trackball.MouseMove(x, y);
break;
}
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, 1, 0.1, 100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,0,6, 0,0,0, 0,1,0);
glRotatef(130, 1, 1, 0);
glTranslatef(0, 1, 1);
// trackball.SetPosition(Similarityf(Point3f(1, 0, 0)));
// trackball.local.sca = 0.5;
trackball.GetView();
trackball.Apply();
trackball.Draw();
glColor3f(0, 1, 0);
glutWireCube(1);
SDL_GL_SwapBuffers();
}
// Clean up
SDL_Quit();
return -1;
}
+21
View File
@@ -0,0 +1,21 @@
Microsoft Visual Studio Solution File, Format Version 7.00
Project("{EAF909A5-FA59-4C3D-9431-0FCC20D5BCF9}") = "trackball", "trackball.icproj", "{BFD1CCD1-E974-402C-9A01-4289A1A420D5}"
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
ConfigName.0 = Debug
ConfigName.1 = Release
EndGlobalSection
GlobalSection(ProjectDependencies) = postSolution
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{BFD1CCD1-E974-402C-9A01-4289A1A420D5}.Debug.ActiveCfg = Debug|Win32
{BFD1CCD1-E974-402C-9A01-4289A1A420D5}.Debug.Build.0 = Debug|Win32
{BFD1CCD1-E974-402C-9A01-4289A1A420D5}.Release.ActiveCfg = Release|Win32
{BFD1CCD1-E974-402C-9A01-4289A1A420D5}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal
+156
View File
@@ -0,0 +1,156 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.00"
Name="trackball"
ProjectGUID="{378B2139-BFC0-47F0-A4C0-8E4616C2FB88}"
Keyword="Win32Proj"
OwnerKey="{EAF909A5-FA59-4C3D-9431-0FCC20D5BCF9}">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="c:\sf\vcg"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="5"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="SDL.lib opengl32.lib glu32.lib"
OutputFile="$(OutDir)/trackball.exe"
LinkIncremental="2"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/trackball.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
OmitFramePointers="TRUE"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
StringPooling="TRUE"
RuntimeLibrary="4"
EnableFunctionLevelLinking="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/trackball.exe"
LinkIncremental="1"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
</Configuration>
</Configurations>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
<File
RelativePath="main.cpp">
</File>
<File
RelativePath="..\..\..\wrap\gui\trackball.cpp">
</File>
<File
RelativePath="..\..\..\wrap\gui\trackmode.cpp">
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc">
<File
RelativePath="..\..\..\vcg\math\base.h">
</File>
<File
RelativePath="..\..\..\wrap\gui\frustum.h">
</File>
<File
RelativePath="..\..\..\wrap\gl\math.h">
</File>
<File
RelativePath="..\..\..\vcg\math\matrix44.h">
</File>
<File
RelativePath="..\..\..\vcg\math\quaternion.h">
</File>
<File
RelativePath="..\..\..\vcg\math\similarity.h">
</File>
<File
RelativePath="..\..\..\wrap\gui\trackball.h">
</File>
<File
RelativePath="..\..\..\wrap\gui\trackmode.h">
</File>
<File
RelativePath="..\..\..\wrap\gui\view.h">
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>