diff --git a/J3DEngine/transtest.cpp b/J3DEngine/transtest.cpp index 64b42b5..463f6a6 100644 --- a/J3DEngine/transtest.cpp +++ b/J3DEngine/transtest.cpp @@ -12,7 +12,7 @@ #include #include "Global.h" #include "MVSEngine.h" - +#include "third_party/cmdLine/cmdLine.h" HWND m_hWnd; @@ -769,11 +769,14 @@ void MsgProc(UINT msg, WPARAM wp, LPARAM lp) int main() { + std::cout << "\n正在初始化引擎,请稍等\n"; MSG msg; SetTimer(NULL, 0, 1000, NULL); _mkdir("C:\\ProgramData\\J3DEngine"); HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE); DWORD mode; + srand(time(NULL)); + int sz = rand() % 300; GetConsoleMode(hStdin, &mode); mode &= ~ENABLE_QUICK_EDIT_MODE; //移除快速编辑模式 mode &= ~ENABLE_INSERT_MODE; //移除插入模式 @@ -793,8 +796,11 @@ int main() SendMessage(m_hWnd, WM_USER, tid, 0); } + for (int i = 0; i < sz; ++i)Sleep(20); + + std::cout << "\n-----------------------------------" << std::endl; - std::cout << " 欢迎使用J3DEngine V1.6 " << std::endl; + std::cout << " 欢迎使用J3DEngine V1.7 " << std::endl; std::cout << " 程序初始化成功 " << std::endl; std::cout << " 请使用J3DGUI程序发起指令 " << std::endl; std::cout << " @Basic All rights reserved " << std::endl; diff --git a/J3DEngine/x64/Release/Global.obj b/J3DEngine/x64/Release/Global.obj index 4671971..e0b3aea 100644 Binary files a/J3DEngine/x64/Release/Global.obj and b/J3DEngine/x64/Release/Global.obj differ diff --git a/J3DEngine/x64/Release/J3DEngine.Build.CppClean.log b/J3DEngine/x64/Release/J3DEngine.Build.CppClean.log deleted file mode 100644 index 6bb7929..0000000 --- a/J3DEngine/x64/Release/J3DEngine.Build.CppClean.log +++ /dev/null @@ -1,17 +0,0 @@ -e:\work\jwl3d\j3dengine\x64\release\vc141.pdb -e:\work\jwl3d\j3dengine\x64\release\transtest.obj -e:\work\jwl3d\j3dengine\x64\release\global.obj -c:\openmvs\build\openmvg\windows-amd64-release\release\openmvg_main_computematches.lib -c:\openmvs\build\openmvg\windows-amd64-release\release\openmvg_main_computematches.exp -e:\work\jwl3d\x64\release\j3dengine.exe -e:\work\jwl3d\j3dengine\x64\release\j3dengine.res -e:\work\jwl3d\j3dengine\x64\release\j3dengine.tlog\cl.command.1.tlog -e:\work\jwl3d\j3dengine\x64\release\j3dengine.tlog\cl.read.1.tlog -e:\work\jwl3d\j3dengine\x64\release\j3dengine.tlog\cl.write.1.tlog -e:\work\jwl3d\j3dengine\x64\release\j3dengine.tlog\j3dengine.write.1u.tlog -e:\work\jwl3d\j3dengine\x64\release\j3dengine.tlog\link.command.1.tlog -e:\work\jwl3d\j3dengine\x64\release\j3dengine.tlog\link.read.1.tlog -e:\work\jwl3d\j3dengine\x64\release\j3dengine.tlog\link.write.1.tlog -e:\work\jwl3d\j3dengine\x64\release\j3dengine.tlog\rc.command.1.tlog -e:\work\jwl3d\j3dengine\x64\release\j3dengine.tlog\rc.read.1.tlog -e:\work\jwl3d\j3dengine\x64\release\j3dengine.tlog\rc.write.1.tlog diff --git a/J3DEngine/x64/Release/J3DEngine.res b/J3DEngine/x64/Release/J3DEngine.res index c88b630..91e32f4 100644 Binary files a/J3DEngine/x64/Release/J3DEngine.res and b/J3DEngine/x64/Release/J3DEngine.res differ diff --git a/J3DEngine/x64/Release/transtest.obj b/J3DEngine/x64/Release/transtest.obj index 8a6edcf..7f0b64a 100644 Binary files a/J3DEngine/x64/Release/transtest.obj and b/J3DEngine/x64/Release/transtest.obj differ diff --git a/J3DEngine/x64/Release/vc141.pdb b/J3DEngine/x64/Release/vc141.pdb index db7c5ae..5c9d964 100644 Binary files a/J3DEngine/x64/Release/vc141.pdb and b/J3DEngine/x64/Release/vc141.pdb differ diff --git a/J3DGUI/QT3DReconstruction.cpp b/J3DGUI/QT3DReconstruction.cpp index 8bb74c2..4b482c4 100644 --- a/J3DGUI/QT3DReconstruction.cpp +++ b/J3DGUI/QT3DReconstruction.cpp @@ -31,6 +31,7 @@ QT3DReconstruction::QT3DReconstruction(QWidget *parent) setWindowFlags(windowFlags()& ~Qt::WindowMaximizeButtonHint); setFixedSize(this->width(), this->height()); viewer = nullptr; + ViewerAva = false; } @@ -122,7 +123,18 @@ void QT3DReconstruction::timerSlot() return; } - openView(fileName); + if (ViewerAva == true) + { + const char* path[2]; + path[0] = fileName.toStdString().c_str(); + path[1] = NULL; + viewer->window.Drop(1, path); + } + else + { + openViewCompatibility(fileName); + } + } else if (temp == "densifypointcloud") { QString fileName = Global::densifyWorkingDir + "/DenseCloud.J3D"; @@ -132,7 +144,17 @@ void QT3DReconstruction::timerSlot() return; } - openView(fileName); + if (ViewerAva == true) + { + const char* path[2]; + path[0] = fileName.toStdString().c_str(); + path[1] = NULL; + viewer->window.Drop(1, path); + } + else + { + openViewCompatibility(fileName); + } } else if (temp == "reconstructmesh") { QString fileName = Global::reconstructMeshWorkingDir + "/TIN_Mesh.J3D"; @@ -142,7 +164,17 @@ void QT3DReconstruction::timerSlot() return; } - openView(fileName); + if (ViewerAva == true) + { + const char* path[2]; + path[0] = fileName.toStdString().c_str(); + path[1] = NULL; + viewer->window.Drop(1, path); + } + else + { + openViewCompatibility(fileName); + } } else if (temp == "texturemesh") { QString fileName = Global::reconstructMeshWorkingDir + "/TEXTURE_Mesh.J3D"; @@ -152,7 +184,17 @@ void QT3DReconstruction::timerSlot() return; } - openView(fileName); + if (ViewerAva == true) + { + const char* path[2]; + path[0] = fileName.toStdString().c_str(); + path[1] = NULL; + viewer->window.Drop(1, path); + } + else + { + openViewCompatibility(fileName); + } } QMessageBox::information(NULL, u8"完成", u8"任务完成! ", QMessageBox::Ok, QMessageBox::Ok); Global::tasking = false; @@ -274,7 +316,7 @@ void QT3DReconstruction::on_actionopen_mvs_file_triggered() return; } - if (viewer == nullptr) + if (ViewerAva == false) { openView(fileName); return; @@ -322,6 +364,7 @@ bool QT3DReconstruction::openView(QString fileName) viewer->window.SetVisible(true); // enter viewer loop + ViewerAva = true; viewer->Loop(); FinalizeViewer(); return true; diff --git a/J3DGUI/j3dviewer.cpp b/J3DGUI/j3dviewer.cpp deleted file mode 100644 index 9fa7160..0000000 --- a/J3DGUI/j3dviewer.cpp +++ /dev/null @@ -1,235 +0,0 @@ -#include "j3dviewer.h" - - - -j3dviewer::j3dviewer(QWidget *parent) - : QOpenGLWidget{ parent } -{ - OldMouse = new Position3D(); - Mouse = new Position3D(); - - NewEye = new Vector3D(1, 0, 0); - NewUp = new Vector3D(0, 0, 1); - NewView = new Vector3D(0, 0, 0); - - AuxY = new Vector3D(0, 1, 0); - AuxZ = new Vector3D(); - *AuxZ = (Vector3D)*NewEye - (Vector3D)*NewView; - AuxX = new Vector3D(); - *AuxX = Vector3D::crossProduct(*AuxY, *AuxZ); - AuxX->normalize(); - - TempTranslateVec = new Vector3D(0, 0, 0); - TempscaleFactor = 10; - - this->setFocusPolicy(Qt::StrongFocus); - this->ply = Global::ply; -} -j3dviewer::~j3dviewer() { - delete OldMouse; - delete Mouse; - delete NewEye; - delete NewUp; - delete NewView; - delete AuxX; - delete AuxY; - delete AuxZ; - delete TempTranslateVec; -} - -void j3dviewer::initializeGL() -{ - initializeOpenGLFunctions(); - init_CoordinaryDisplayList(); - - glShadeModel(GL_SMOOTH); - //glClearDepth(1.0f); - - //glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - //鏉愯川鍙嶅厜鎬ц缃 - GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; //闀滈潰鍙嶅皠鍙傛暟 - GLfloat mat_shininess[] = { 50.0 }; //楂樺厜鎸囨暟 - GLfloat light_position[] = { 0.0, 1.0, 1.0, 0.0 }; - GLfloat white_light[] = { 1.0, 1.0, 1.0, 1.0 }; //鐏綅缃(1,1,1), 鏈鍚1-寮鍏 - GLfloat Light_Model_Ambient[] = { 0.2, 0.2, 0.2, 1.0 }; //鐜鍏夊弬鏁 - - //鐏厜璁剧疆 - glLightfv(GL_LIGHT0, GL_POSITION, light_position); - glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light); //鏁e皠鍏夊睘鎬 - glLightfv(GL_LIGHT0, GL_SPECULAR, white_light); //闀滈潰鍙嶅皠鍏 - glLightModelfv(GL_LIGHT_MODEL_AMBIENT, Light_Model_Ambient); //鐜鍏夊弬鏁 - - - glEnable(GL_LIGHT0); //鎵撳紑0#鐏 - - GLfloat material_color[4] = { 1,1,1,1.0f }; - GLfloat material_specular[4] = { 1.0f,1.0f,1.0f,0.5f }; - GLfloat material_ambient[4] = { 0.5f,0.5f,0.5f,0.5f }; - - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material_specular); - glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material_color); - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, material_ambient); - glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 20); - - - glEnable(GL_DEPTH_TEST); - //glDepthFunc(GL_LEQUAL); - //glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); - glViewport(0, 0, 1800, 900); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(-20, 20, -10, 10, -10.0, 10.0); - - -} - -void j3dviewer::paintGL() -{ - glClearColor(0.9019f, 0.9019f, 0.9821f, 0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - *NewView = *NewEye*-1; - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(TempTranslateVec->X() / 40, TempTranslateVec->Y() / 40, TempTranslateVec->Z() / 40); - glScalef(TempscaleFactor, TempscaleFactor, 1); - gluLookAt(NewEye->X(), NewEye->Y(), NewEye->Z(), - NewView->X(), NewView->Y(), NewView->Z(), - NewUp->X(), NewUp->Y(), NewUp->Z()); - glCallList(ID_COORDINATY); - glEnable(GL_TEXTURE_2D); - glColor3f(1.0, 0.0, 0.0); - - if (this->ply->available == true) { - this->ply->render(); - } - glDisable(GL_TEXTURE_2D); - //glutSwapBuffers(); -} - -void j3dviewer::resizeGL(int w, int h) -{ - //glViewport(0, -(w - h) / 2, w, w); -} - -void j3dviewer::mousePressEvent(QMouseEvent *e) -{ - this->getInitPos(e->x(), e->y()); -} - -void j3dviewer::mouseMoveEvent(QMouseEvent *e) -{ - if (e->buttons()&Qt::LeftButton) - { - this->executeRotateOperation(e->x(), e->y()); - } - else if (e->buttons()&Qt::RightButton) - { - this->executeTranslateOperation(e->x(), e->y()); - } - - update(); -} - -void j3dviewer::wheelEvent(QWheelEvent *e) -{ - if (e->delta() >= 0) - { - this->executeScaleOperation(1.5); - } - else - { - this->executeScaleOperation(-1.5); - } - update(); -} - -void j3dviewer::getInitPos(int x, int y) -{ - Mouse->setX(x); - Mouse->setY(y); - *OldMouse = *Mouse; -} - -void j3dviewer::executeRotateOperation(int x, int y) -{ - Mouse->setX(x); - Mouse->setY(y); - - Vector3D MouseTrace = *AuxY*(OldMouse->Y() - Mouse->Y()) + *AuxX*(Mouse->X() - OldMouse->X()); - Vector3D RotateAsix = Vector3D::crossProduct(MouseTrace, *AuxZ); - RotateAsix.normalize(); - - float angle = MouseTrace.length(); - Matrix4D rotatMatrix = Matrix4D::getRotateMatrix(angle, RotateAsix); - - *NewEye = rotatMatrix * (*NewEye); - *NewUp = rotatMatrix * (*NewUp); - - NewUp->normalize(); - - *AuxY = *NewUp; - *AuxZ = (Vector3D)*NewEye - (Vector3D)*NewView; - *AuxX = Vector3D::crossProduct(*AuxY, *AuxZ); - AuxX->normalize(); - /*鏇存柊榧犳爣 */ - *OldMouse = *Mouse; -} - -void j3dviewer::executeScaleOperation(float factor) -{ - if (TempscaleFactor <= 0) - { - TempscaleFactor = 0.1; - } - else - { - TempscaleFactor += factor; - } -} - -void j3dviewer::executeTranslateOperation(int x, int y) -{ - Mouse->setX(x); - Mouse->setY(y); - Vector3D vec(-OldMouse->X() + Mouse->X(), -Mouse->Y() + OldMouse->Y(), 0); - *TempTranslateVec = *TempTranslateVec + vec; - *OldMouse = *Mouse; -} - -void j3dviewer::init_CoordinaryDisplayList() -{ - ID_COORDINATY = glGenLists(1); - glNewList(ID_COORDINATY, GL_COMPILE); - /*绾㈣壊杞存槸X杞达紝缁胯壊鏄痀杞达紝钃濊壊鏄痁杞 */ - int length = 2; - glLineWidth(4); - glBegin(GL_LINES); - glColor3f(1.0, 0.0, 0.0); - glVertex3f(0.0, 0.0, 0.0); - glVertex3f(length, 0.0, 0.0); - glEnd(); - - glLineWidth(2); - glBegin(GL_LINES); - glColor3f(0.0, 1.0, 0.0); - glVertex3f(0.0, 0.0, 0.0); - glVertex3f(0.0, length, 0.0); - glEnd(); - - glLineWidth(0.5); - glBegin(GL_LINES); - glColor3f(0.0, 0.0, 1.0); - glVertex3f(0.0, 0.0, 0.0); - glVertex3f(0.0, 0.0, length); - glEnd(); - - glLineWidth(1); - glEnd(); - glEndList(); -} - -void j3dviewer::setPly() { - this->ply = Global::ply; -} \ No newline at end of file diff --git a/J3DGUI/j3dviewer.h b/J3DGUI/j3dviewer.h deleted file mode 100644 index 9827ee3..0000000 --- a/J3DGUI/j3dviewer.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef J3DVIEWER_H -#define J3DVIEWER_H -#pragma once -#include "PlyIO.h" -#include -#include -#include - -#include -#include -#include "Global.h" -#include "GLUtil/Vector3D.h" -#include "GLUtil/Position3D.h" -#include "GLUtil/Matrix4D.h" -#include "lpng/png.h" -#include "zlib/zlib.h" -#include -#include - -//class RoamingScenceManager; -class j3dviewer : public QOpenGLWidget, public QOpenGLFunctions -{ - Q_OBJECT -public: - j3dviewer(QWidget *parent = nullptr); - ~j3dviewer(); - PlyIO* ply; - void setPly(); - - - void executeRotateOperation(int x, int y); - void executeScaleOperation(float factor); - void executeTranslateOperation(int x, int y); - void getInitPos(int x, int y); -protected: - void initializeGL() override; - void paintGL() override; - void resizeGL(int w, int h) override; - void mousePressEvent(QMouseEvent*e); - void mouseMoveEvent(QMouseEvent*e); - void wheelEvent(QWheelEvent *e); - -private: - //杈呭姪鍧愭爣绯讳笁鏍硅酱 - Vector3D *AuxX; - Vector3D *AuxY; - Vector3D *AuxZ; - - //鏃嬭浆鍚庤瀵熺偣鏂瑰悜涓庤绾垮悜涓婃柟鍚 - Vector3D*NewEye; - Vector3D*NewUp; - Vector3D *NewView; - - Position3D *OldMouse; - Position3D *Mouse; - - Vector3D *TempTranslateVec; - float TempscaleFactor; - - int ID_COORDINATY; - void init_CoordinaryDisplayList(); - -}; - - -#endif // J3DVIEWER_H diff --git a/MVSEngine/Camera.cpp b/MVSEngine/Camera.cpp deleted file mode 100644 index b217c2d..0000000 --- a/MVSEngine/Camera.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Camera.cpp - * - * Copyright (c) 2014-2015 SEACAVE - * - * Author(s): - * - * cDc - * - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * - * Additional Terms: - * - * You are required to preserve legal notices and author attributions in - * that material or in the Appropriate Legal Notices displayed by works - * containing it. - */ - -#include "Common.h" -#include "Camera.h" - -using namespace VIEWER; - - -// D E F I N E S /////////////////////////////////////////////////// - - -// S T R U C T S /////////////////////////////////////////////////// - -Camera::Camera(const AABB3d& _box, double _fov) - : - box(_box), - width(0), height(0), - rotation(Eigen::Quaterniond::Identity()), - center(Eigen::Vector3d::Zero()), - dist(0), radius(100), fov(_fov), - scaleF(1.f), - prevCamID(NO_ID), currentCamID(NO_ID), maxCamID(0) -{ - Reset(); -} - -void Camera::CopyOf(const Camera& rhs) -{ - rotation = rhs.rotation; - center = rhs.center; - dist = rhs.dist; - radius = rhs.radius; - fov = rhs.fov; -} - - -void Camera::Init(const AABB3d& _box) -{ - box = _box; - Reset(); -} - -void Camera::Reset() -{ - center = box.GetCenter(); - radius = box.GetSize().norm()*0.5; - rotation = Eigen::Quaterniond::Identity(); - scaleF = 1.f; - prevCamID = currentCamID = NO_ID; - fov = 40; - dist = radius * 0.5 / SIN(D2R(fov)); - Resize(width, height); -} - -void Camera::Resize(int _width, int _height) -{ - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - const GLfloat zNear = 1e-2f; - const GLfloat zFar = 1e5f; - width = _width; height = _height; - GLfloat aspect = float(width)/float(height); - GLfloat fH = TAN(FD2R((float)fov)) * zNear; - GLfloat fW = fH * aspect; - glFrustum(-fW, fW, -fH, fH, zNear, zFar); -} - -void Camera::SetFOV(double _fov) -{ - fov = _fov; - Resize(width, height); -} - - -Eigen::Vector3d Camera::GetPosition() const -{ - const Eigen::Matrix3d R(rotation.toRotationMatrix()); - const Eigen::Vector3d eye(0, 0, dist); - return R * eye + center; -} - -Eigen::Matrix4d Camera::GetLookAt() const -{ - const Eigen::Matrix3d R(rotation.toRotationMatrix()); - const Eigen::Vector3d eye(R.col(2) * dist + center); - const Eigen::Vector3d up(R.col(1)); - - const Eigen::Vector3d n((center-eye).normalized()); - const Eigen::Vector3d s(n.cross(up)); - const Eigen::Vector3d v(s.cross(n)); - - Eigen::Matrix4d m; - m << - s(0), s(1), s(2), -eye.dot(s), - v(0), v(1), v(2), -eye.dot(v), - -n(0), -n(1), -n(2), eye.dot(n), - 0.0, 0.0, 0.0, 1.0; - return m; -} -void Camera::GetLookAt(Eigen::Vector3d& _eye, Eigen::Vector3d& _center, Eigen::Vector3d& _up) const -{ - const Eigen::Matrix3d R(rotation.toRotationMatrix()); - const Eigen::Vector3d eye(0, 0, dist); - const Eigen::Vector3d up(0, 1, 0); - - _eye = R * eye + center; - _center = center; - _up = R * up; -} - -void Camera::Rotate(const Eigen::Vector2d& pos, const Eigen::Vector2d& prevPos) -{ - if (pos.isApprox(prevPos, ZERO_TOLERANCE)) - return; - - Eigen::Vector3d oldp(prevPos.x(), prevPos.y(), 0); - Eigen::Vector3d newp(pos.x(), pos.y(), 0); - const double radius_virtual_sphere(0.9); - Project2Sphere(radius_virtual_sphere, oldp); - Project2Sphere(radius_virtual_sphere, newp); - Eigen::Quaterniond dr; - dr.setFromTwoVectors(newp, oldp); - rotation *= dr; - - // disable camera view mode - prevCamID = currentCamID; -} - -void Camera::Project2Sphere(double radius, Eigen::Vector3d& p) const -{ - p.z() = 0; - const double d = p.x()* p.x()+ p.y() * p.y(); - const double r = radius * radius; - if (d < r) p.z() = SQRT(r - d); - else p *= radius / p.norm(); -} -/*----------------------------------------------------------------*/ diff --git a/MVSEngine/Camera.h b/MVSEngine/Camera.h deleted file mode 100644 index 37d9823..0000000 --- a/MVSEngine/Camera.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Camera.h - * - * Copyright (c) 2014-2015 SEACAVE - * - * Author(s): - * - * cDc - * - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * - * Additional Terms: - * - * You are required to preserve legal notices and author attributions in - * that material or in the Appropriate Legal Notices displayed by works - * containing it. - */ - -#ifndef _VIEWER_CAMERA_H_ -#define _VIEWER_CAMERA_H_ - - -// I N C L U D E S ///////////////////////////////////////////////// - - -// D E F I N E S /////////////////////////////////////////////////// - - -// S T R U C T S /////////////////////////////////////////////////// - -namespace VIEWER { - -class Camera -{ -public: - EIGEN_MAKE_ALIGNED_OPERATOR_NEW - - AABB3d box; - int width, height; - Eigen::Quaterniond rotation; - Eigen::Vector3d center; - double dist; - double radius; - double fov; - float scaleF; - MVS::IIndex prevCamID, currentCamID, maxCamID; - -public: - explicit Camera(const AABB3d& _box=AABB3d(true), double _fov=40); - void CopyOf(const Camera&); - - void Init(const AABB3d&); - void Reset(); - void Resize(int _width, int _height); - void SetFOV(double _fov); - - Eigen::Vector3d GetPosition() const; - Eigen::Matrix4d GetLookAt() const; - void GetLookAt(Eigen::Vector3d& eye, Eigen::Vector3d& center, Eigen::Vector3d& up) const; - void Rotate(const Eigen::Vector2d& pos, const Eigen::Vector2d& prevPos); - -protected: - void Project2Sphere(double radius, Eigen::Vector3d& p) const; -}; -typedef CSharedPtr CameraPtr; -/*----------------------------------------------------------------*/ - -} // namespace VIEWER - -#endif // _VIEWER_CAMERA_H_ diff --git a/MVSEngine/Common.cpp b/MVSEngine/Common.cpp deleted file mode 100644 index ec1dc0a..0000000 --- a/MVSEngine/Common.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Common.cpp - * - * Copyright (c) 2014-2015 SEACAVE - * - * Author(s): - * - * cDc - * - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * - * Additional Terms: - * - * You are required to preserve legal notices and author attributions in - * that material or in the Appropriate Legal Notices displayed by works - * containing it. - */ - -// Source file that includes just the standard includes -// Common.pch will be the pre-compiled header -// Common.obj will contain the pre-compiled type information - -#include "Common.h" diff --git a/MVSEngine/Common.h b/MVSEngine/Common.h deleted file mode 100644 index 2a15abb..0000000 --- a/MVSEngine/Common.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Common.h - * - * Copyright (c) 2014-2015 SEACAVE - * - * Author(s): - * - * cDc - * - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * - * Additional Terms: - * - * You are required to preserve legal notices and author attributions in - * that material or in the Appropriate Legal Notices displayed by works - * containing it. - */ - -#ifndef _VIEWER_COMMON_H_ -#define _VIEWER_COMMON_H_ - - -// I N C L U D E S ///////////////////////////////////////////////// - -#include -#include "libs/MVS/Common.h" -#include "libs/MVS/Scene.h" - -#if defined(_MSC_VER) -#include -#elif defined(__APPLE__) -#include -#else -#include -#endif -#include - - -// D E F I N E S /////////////////////////////////////////////////// - - -// P R O T O T Y P E S ///////////////////////////////////////////// - -using namespace SEACAVE; - -namespace VIEWER { - -// the conversion matrix from OpenGL default coordinate system -// to the camera coordinate system: -// [ 1 0 0 0] * [ x ] = [ x ] -// 0 -1 0 0 y -y -// 0 0 -1 0 z -z -// 0 0 0 1 1 1 -static const GLfloat gs_convert[4][4] = { - {1.f, 0.f, 0.f, 0.f}, - {0.f, -1.f, 0.f, 0.f}, - {0.f, 0.f, -1.f, 0.f}, - {0.f, 0.f, 0.f, 1.f}}; - -/// given rotation matrix R and translation vector t, -/// column-major matrix m is equal to: -/// [ R11 R12 R13 t.x ] -/// | R21 R22 R23 t.y | -/// | R31 R32 R33 t.z | -/// [ 0.0 0.0 0.0 1.0 ] -// -// World to Local -inline Eigen::Matrix4d TransW2L(const Eigen::Matrix3d& R, const Eigen::Vector3d& t) -{ - Eigen::Matrix4d m(Eigen::Matrix4d::Identity()); - m.block(0,0,3,3) = R; - m.block(0,3,3,1) = t; - return m; -} -// Local to World -// same as above, but with the inverse of the two -inline Eigen::Matrix4d TransL2W(const Eigen::Matrix3d& R, const Eigen::Vector3d& t) -{ - Eigen::Matrix4d m(Eigen::Matrix4d::Identity()); - m.block(0,0,3,3) = R.transpose(); - m.block(0,3,3,1) = -t; - return m; -} -/*----------------------------------------------------------------*/ - -} // namespace MVS - -#endif // _VIEWER_COMMON_H_ diff --git a/MVSEngine/Image.cpp b/MVSEngine/Image.cpp deleted file mode 100644 index 4268196..0000000 --- a/MVSEngine/Image.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Image.cpp - * - * Copyright (c) 2014-2015 SEACAVE - * - * Author(s): - * - * cDc - * - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * - * Additional Terms: - * - * You are required to preserve legal notices and author attributions in - * that material or in the Appropriate Legal Notices displayed by works - * containing it. - */ - -#include "Common.h" -#include "Image.h" - -using namespace VIEWER; - - -// D E F I N E S /////////////////////////////////////////////////// - - -// S T R U C T S /////////////////////////////////////////////////// - -Image::Image(MVS::IIndex _idx) - : - idx(_idx), - texture(0) -{ -} -Image::~Image() -{ - Release(); -} - -void Image::Release() -{ - if (IsValid()) { - glDeleteTextures(1, &texture); - texture = 0; - } - ReleaseImage(); -} -void Image::ReleaseImage() -{ - if (IsImageValid()) { - cv::Mat* const p(pImage); - Thread::safeExchange(pImage.ptr, (int_t)IMG_NULL); - delete p; - } -} - -void Image::SetImageLoading() -{ - ASSERT(IsImageEmpty()); - Thread::safeExchange(pImage.ptr, (int_t)IMG_LOADING); -} -void Image::AssignImage(cv::InputArray img) -{ - ASSERT(IsImageLoading()); - ImagePtrInt pImg(new cv::Mat(img.getMat())); - if (pImg.pImage->cols%4 != 0) { - // make sure the width is multiple of 4 (seems to be an OpenGL limitation) - cv::resize(*pImg.pImage, *pImg.pImage, cv::Size((pImg.pImage->cols/4)*4, pImg.pImage->rows), 0, 0, cv::INTER_AREA); - } - Thread::safeExchange(pImage.ptr, pImg.ptr); -} -bool Image::TransferImage() -{ - if (!IsImageValid()) - return false; - SetImage(*pImage); - glfwPostEmptyEvent(); - ReleaseImage(); - return true; -} - -void Image::SetImage(cv::InputArray img) -{ - cv::Mat image(img.getMat()); - glEnable(GL_TEXTURE_2D); - // create texture - glGenTextures(1, &texture); - // select our current texture - glBindTexture(GL_TEXTURE_2D, texture); - // load texture - width = image.cols; - height = image.rows; - ASSERT(image.channels() == 1 || image.channels() == 3); - ASSERT(image.isContinuous()); - glTexImage2D(GL_TEXTURE_2D, - 0, image.channels(), - width, height, - 0, (image.channels() == 1) ? GL_LUMINANCE : GL_BGR, - GL_UNSIGNED_BYTE, image.ptr()); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); -} -void Image::GenerateMipmap() const { - glBindTexture(GL_TEXTURE_2D, texture); - glGenerateMipmap(GL_TEXTURE_2D); -} -void Image::Bind() const { - glBindTexture(GL_TEXTURE_2D, texture); -} -/*----------------------------------------------------------------*/ diff --git a/MVSEngine/Image.h b/MVSEngine/Image.h deleted file mode 100644 index 41c1851..0000000 --- a/MVSEngine/Image.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Image.h - * - * Copyright (c) 2014-2015 SEACAVE - * - * Author(s): - * - * cDc - * - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * - * Additional Terms: - * - * You are required to preserve legal notices and author attributions in - * that material or in the Appropriate Legal Notices displayed by works - * containing it. - */ - -#ifndef _VIEWER_IMAGE_H_ -#define _VIEWER_IMAGE_H_ - - -// I N C L U D E S ///////////////////////////////////////////////// - - -// D E F I N E S /////////////////////////////////////////////////// - - -// S T R U C T S /////////////////////////////////////////////////// - -namespace VIEWER { - -class Image -{ -public: - typedef CLISTDEFIDX(Image,uint32_t) ImageArr; - enum { - IMG_NULL = 0, - IMG_LOADING, - IMG_VALID - }; - union ImagePtrInt { - cv::Mat* pImage; - int_t ptr; - inline ImagePtrInt() : ptr(IMG_NULL) {} - inline ImagePtrInt(cv::Mat* p) : pImage(p) {} - inline operator cv::Mat* () const { return pImage; } - inline operator cv::Mat*& () { return pImage; } - }; - -public: - MVS::IIndex idx; // image index in the current scene - int width, height; - GLuint texture; - double opacity; - ImagePtrInt pImage; - -public: - Image(MVS::IIndex = NO_ID); - ~Image(); - - void Release(); - void ReleaseImage(); - inline bool IsValid() const { return texture > 0; } - inline bool IsImageEmpty() const { return pImage.ptr == IMG_NULL; } - inline bool IsImageLoading() const { return pImage.ptr == IMG_LOADING; } - inline bool IsImageValid() const { return pImage.ptr >= IMG_VALID; } - - void SetImageLoading(); - void AssignImage(cv::InputArray); - bool TransferImage(); - - void SetImage(cv::InputArray); - void GenerateMipmap() const; - void Bind() const; - -protected: -}; -typedef Image::ImageArr ImageArr; -/*----------------------------------------------------------------*/ - -} // namespace VIEWER - -#endif // _VIEWER_IMAGE_H_ diff --git a/MVSEngine/Scene.cpp b/MVSEngine/Scene.cpp deleted file mode 100644 index 792b30d..0000000 --- a/MVSEngine/Scene.cpp +++ /dev/null @@ -1,696 +0,0 @@ -/* - * Scene.cpp - * - * Copyright (c) 2014-2015 SEACAVE - * - * Author(s): - * - * cDc - * - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * - * Additional Terms: - * - * You are required to preserve legal notices and author attributions in - * that material or in the Appropriate Legal Notices displayed by works - * containing it. - */ - -#include "Common.h" -#include "Scene.h" - -using namespace VIEWER; - - -// D E F I N E S /////////////////////////////////////////////////// - -#define IMAGE_MAX_RESOLUTION 1024 - - -// S T R U C T S /////////////////////////////////////////////////// - -struct IndexDist { - IDX idx; - REAL dist; - - inline IndexDist() : dist(REAL(FLT_MAX)) {} - inline bool IsValid() const { return dist < REAL(FLT_MAX); } -}; - -struct IntersectRayPoints { - typedef MVS::PointCloud Scene; - typedef VIEWER::Scene::OctreePoints Octree; - typedef typename Octree::IDX_TYPE IDX; - typedef TCone Cone3; - typedef TConeIntersect Cone3Intersect; - - const Scene& scene; - const Cone3 cone; - const Cone3Intersect coneIntersect; - const unsigned minViews; - IndexDist pick; - - IntersectRayPoints(const Octree& octree, const Ray3& _ray, const Scene& _scene, unsigned _minViews) - : scene(_scene), cone(_ray, D2R(REAL(0.5))), coneIntersect(cone), minViews(_minViews) - { - octree.Collect(*this, *this); - } - - inline bool Intersects(const typename Octree::POINT_TYPE& center, typename Octree::Type radius) const { - return coneIntersect(Sphere3(center.cast(), REAL(radius)*SQRT_3)); - } - - void operator () (const IDX* idices, IDX size) { - // test ray-point intersection and keep the closest - FOREACHRAWPTR(pIdx, idices, size) { - const MVS::PointCloud::Index idx(*pIdx); - if (!scene.pointViews.IsEmpty() && scene.pointViews[idx].size() < minViews) - continue; - const MVS::PointCloud::Point& X = scene.points[idx]; - REAL dist; - if (coneIntersect.Classify(Cast(X), dist) == VISIBLE) { - ASSERT(dist >= 0); - if (pick.dist > dist) { - pick.dist = dist; - pick.idx = idx; - } - } - } - } -}; - -struct IntersectRayMesh { - typedef MVS::Mesh Scene; - typedef VIEWER::Scene::OctreeMesh Octree; - typedef typename Octree::IDX_TYPE IDX; - - const Scene& scene; - const Ray3& ray; - IndexDist pick; - - IntersectRayMesh(const Octree& octree, const Ray3& _ray, const Scene& _scene) - : scene(_scene), ray(_ray) - { - octree.Collect(*this, *this); - } - - inline bool Intersects(const typename Octree::POINT_TYPE& center, typename Octree::Type radius) const { - return ray.Intersects(AABB3f(center, radius)); - } - - void operator () (const IDX* idices, IDX size) { - // store all intersected faces only once - typedef std::unordered_set FaceSet; - FaceSet set; - FOREACHRAWPTR(pIdx, idices, size) { - const MVS::Mesh::VIndex idxVertex((MVS::Mesh::VIndex)*pIdx); - const MVS::Mesh::FaceIdxArr& faces = scene.vertexFaces[idxVertex]; - set.insert(faces.begin(), faces.end()); - } - // test face intersection and keep the closest - for (MVS::Mesh::FIndex idxFace: set) { - const MVS::Mesh::Face& face = scene.faces[idxFace]; - REAL dist; - if (ray.Intersects(Triangle3(Cast(scene.vertices[face[0]]), Cast(scene.vertices[face[1]]), Cast(scene.vertices[face[2]])), &dist)) { - ASSERT(dist >= 0); - if (pick.dist > dist) { - pick.dist = dist; - pick.idx = idxFace; - } - } - } - } -}; -/*----------------------------------------------------------------*/ - - -// S T R U C T S /////////////////////////////////////////////////// - -enum EVENT_TYPE { - EVT_JOB = 0, - EVT_CLOSE, -}; - -class EVTClose : public Event -{ -public: - EVTClose() : Event(EVT_CLOSE) {} -}; -class EVTLoadImage : public Event -{ -public: - Scene* pScene; - MVS::IIndex idx; - unsigned nMaxResolution; - bool Run(void*) { - Image& image = pScene->images[idx]; - ASSERT(image.idx != NO_ID); - MVS::Image& imageData = pScene->scene.images[image.idx]; - ASSERT(imageData.IsValid()); - if (imageData.image.empty() && !imageData.ReloadImage(nMaxResolution)) - return false; - imageData.UpdateCamera(pScene->scene.platforms); - image.AssignImage(imageData.image); - imageData.ReleaseImage(); - glfwPostEmptyEvent(); - return true; - } - EVTLoadImage(Scene* _pScene, MVS::IIndex _idx, unsigned _nMaxResolution=0) - : Event(EVT_JOB), pScene(_pScene), idx(_idx), nMaxResolution(_nMaxResolution) {} -}; -class EVTComputeOctree : public Event -{ -public: - Scene* pScene; - bool Run(void*) { - MVS::Scene& scene = pScene->scene; - if (!scene.mesh.IsEmpty()) { - Scene::OctreeMesh octMesh(scene.mesh.vertices); - scene.mesh.ListIncidenteFaces(); - pScene->octMesh.Swap(octMesh); - } else - if (!scene.pointcloud.IsEmpty()) { - Scene::OctreePoints octPoints(scene.pointcloud.points); - pScene->octPoints.Swap(octPoints); - } - return true; - } - EVTComputeOctree(Scene* _pScene) - : Event(EVT_JOB), pScene(_pScene) {} -}; - -void* Scene::ThreadWorker(void*) { - while (true) { - CAutoPtr evt(events.GetEvent()); - switch (evt->GetID()) { - case EVT_JOB: - evt->Run(); - break; - case EVT_CLOSE: - return NULL; - default: - ASSERT("Should not happen!" == NULL); - } - } - return NULL; -} -/*----------------------------------------------------------------*/ - - -// S T R U C T S /////////////////////////////////////////////////// - -SEACAVE::EventQueue Scene::events; -SEACAVE::Thread Scene::thread; - -Scene::Scene() - : - listPointCloud(0), - listMesh(0) -{ -} -Scene::~Scene() -{ - Release(); -} - -void Scene::Empty() -{ - ReleasePointCloud(); - ReleaseMesh(); - textures.Release(); - images.Release(); - scene.Release(); - sceneName.clear(); -} -void Scene::Release() -{ - if (!thread.isRunning()) { - events.AddEvent(new EVTClose()); - thread.join(); - } - Empty(); - window.Release(); - glfwTerminate(); -} -void Scene::ReleasePointCloud() -{ - if (listPointCloud) { - glDeleteLists(listPointCloud, 1); - listPointCloud = 0; - } -} -void Scene::ReleaseMesh() -{ - if (listMesh) { - glDeleteLists(listMesh, 1); - listMesh = 0; - } -} - -bool Scene::Init(int width, int height, LPCTSTR windowName, LPCTSTR fileName, LPCTSTR meshFileName) -{ - ASSERT(scene.IsEmpty()); - - // init window - if (glfwInit() == GL_FALSE) - return false; - if (!window.Init(width, height, windowName)) - return false; - if (glewInit() != GLEW_OK) - return false; - name = windowName; - window.clbkOpenScene = DELEGATEBINDCLASS(Window::ClbkOpenScene, &Scene::Open, this); - window.clbkExportScene = DELEGATEBINDCLASS(Window::ClbkExportScene, &Scene::Export, this); - window.clbkRayScene = DELEGATEBINDCLASS(Window::ClbkRayScene, &Scene::CastRay, this); - window.clbkCompilePointCloud = DELEGATEBINDCLASS(Window::ClbkCompilePointCloud, &Scene::CompilePointCloud, this); - window.clbkCompileMesh = DELEGATEBINDCLASS(Window::ClbkCompileMesh, &Scene::CompileMesh, this); - - // init OpenGL - glPolygonMode(GL_FRONT, GL_FILL); - glEnable(GL_DEPTH_TEST); - //glClearColor(0.f, 0.5f, 0.9f, 1.f); - glClearColor(0.9019f, 0.9019f, 0.9821f, 0); - static const float light0_ambient[] = {0.1f, 0.1f, 0.1f, 1.0f}; - static const float light0_diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f}; - static const float light0_position[] = {0.0f, 0.0f, 1000.0f, 0.0f}; - static const float light0_specular[] = {0.4f, 0.4f, 0.4f, 1.0f}; - - glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient); - glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse); - glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular); - glLightfv(GL_LIGHT0, GL_POSITION, light0_position); - glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); - - glEnable(GL_LIGHT0); - glDisable(GL_LIGHTING); - - // init working thread - thread.start(ThreadWorker); - - // open scene or init empty scene - if (fileName == NULL || !Open(fileName, meshFileName)) - window.SetCamera(CameraPtr(new Camera())); - - window.SetVisible(true); - return true; -} -bool Scene::Open(LPCTSTR fileName, LPCTSTR meshFileName) -{ - ASSERT(fileName); - //DEBUG_EXTRA("Loading: '%s'", Util::getFileNameExt(fileName).c_str()); - Empty(); - sceneName = fileName; - - // load the scene - WORKING_FOLDER = Util::getFilePath(fileName); - INIT_WORKING_FOLDER; - if (!scene.Load(fileName, true)) - return false; - if (meshFileName) { - // load given mesh - scene.mesh.Load(meshFileName); - } - if (scene.IsEmpty()) - return false; - - #if 1 - // create octree structure used to accelerate selection functionality - events.AddEvent(new EVTComputeOctree(this)); - #endif - - // init scene - AABB3d bounds(true); - if (!scene.pointcloud.IsEmpty()) { - bounds = scene.pointcloud.GetAABB(MINF(3u,scene.nCalibratedImages)); - if (bounds.IsEmpty()) - bounds = scene.pointcloud.GetAABB(); - } - if (!scene.mesh.IsEmpty()) { - scene.mesh.ComputeNormalFaces(); - bounds.Insert(scene.mesh.GetAABB()); - } - - // init images - images.Reserve(scene.images.size()); - FOREACH(idxImage, scene.images) { - const MVS::Image& imageData = scene.images[idxImage]; - if (!imageData.IsValid()) - continue; - images.AddConstruct(idxImage); - } - - // init and load texture - if (scene.mesh.HasTexture()) { - Image& image = textures.AddEmpty(); - ASSERT(image.idx == NO_ID); - #if 0 - cv::flip(scene.mesh.textureDiffuse, scene.mesh.textureDiffuse, 0); - image.SetImage(scene.mesh.textureDiffuse); - scene.mesh.textureDiffuse.release(); - #else // preserve texture, used only to be able to export the mesh - Image8U3 textureDiffuse; - cv::flip(scene.mesh.textureDiffuse, textureDiffuse, 0); - image.SetImage(textureDiffuse); - #endif - image.GenerateMipmap(); - } - - // init display lists - // compile point-cloud - CompilePointCloud(); - // compile mesh - CompileMesh(); - - // init camera - window.SetCamera(CameraPtr(new Camera(bounds))); - window.camera->maxCamID = images.size(); - window.SetName(String::FormatString((name + _T(": %s")).c_str(), Util::getFileName(fileName).c_str())); - window.Reset(MINF(2u, images.size())); - return true; -} - -// export the scene -bool Scene::Export(LPCTSTR _fileName, LPCTSTR exportType, bool losslessTexture) const -{ - if (!IsOpen()) - return false; - ASSERT(!sceneName.IsEmpty()); - String lastFileName; - const String fileName(_fileName != NULL ? String(_fileName) : sceneName); - const String baseFileName(Util::getFileFullName(fileName)); - const bool bPoints(scene.pointcloud.Save(lastFileName=(baseFileName+_T("_pointcloud.ply")))); - const bool bMesh(scene.mesh.Save(lastFileName=(baseFileName+_T("_mesh")+(exportType?exportType:(Util::getFileExt(fileName)==_T(".obj")?_T(".obj"):_T(".ply")))), true, losslessTexture)); - #if TD_VERBOSE != TD_VERBOSE_OFF - if (VERBOSITY_LEVEL > 2 && (bPoints || bMesh)) - scene.ExportCamerasMLP(Util::getFileFullName(lastFileName)+_T(".mlp"), lastFileName); - #endif - return (bPoints || bMesh); -} - -void Scene::CompilePointCloud() -{ - if (scene.pointcloud.IsEmpty()) - return; - ReleasePointCloud(); - listPointCloud = glGenLists(1); - glNewList(listPointCloud, GL_COMPILE); - ASSERT((window.sparseType&(Window::SPR_POINTS|Window::SPR_LINES)) != 0); - // compile point-cloud - if (!scene.pointcloud.IsEmpty() && (window.sparseType&Window::SPR_POINTS) != 0) { - ASSERT_ARE_SAME_TYPE(float, MVS::PointCloud::Point::Type); - glBegin(GL_POINTS); - glColor3f(0,0,0); - FOREACH(i, scene.pointcloud.points) { - if (!scene.pointcloud.pointViews.IsEmpty() && - scene.pointcloud.pointViews[i].size() < window.minViews) - continue; - if (!scene.pointcloud.colors.IsEmpty()) { - const MVS::PointCloud::Color& c = scene.pointcloud.colors[i]; - glColor3ub(c.r,c.g,c.b); - } - const MVS::PointCloud::Point& X = scene.pointcloud.points[i]; - glVertex3fv(X.ptr()); - } - glEnd(); - } - glEndList(); -} - -void Scene::CompileMesh() -{ - if (scene.mesh.IsEmpty()) - return; - ReleaseMesh(); - listMesh = glGenLists(1); - glNewList(listMesh, GL_COMPILE); - // compile mesh - ASSERT_ARE_SAME_TYPE(float, MVS::Mesh::Vertex::Type); - ASSERT_ARE_SAME_TYPE(float, MVS::Mesh::Normal::Type); - ASSERT_ARE_SAME_TYPE(float, MVS::Mesh::TexCoord::Type); - glColor3f(0, 0, 0); - glBegin(GL_TRIANGLES); - FOREACH(i, scene.mesh.faces) { - const MVS::Mesh::Face& face = scene.mesh.faces[i]; - const MVS::Mesh::Normal& n = scene.mesh.faceNormals[i]; - glNormal3fv(n.ptr()); - for (int j = 0; j < 3; ++j) { - if (!scene.mesh.faceTexcoords.IsEmpty() && window.bRenderTexture) { - const MVS::Mesh::TexCoord& t = scene.mesh.faceTexcoords[i * 3 + j]; - glTexCoord2fv(t.ptr()); - } - const MVS::Mesh::Vertex& p = scene.mesh.vertices[face[j]]; - glVertex3fv(p.ptr()); - } - } - glEnd(); - glEndList(); -} - -void Scene::Draw() -{ - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glPointSize(window.pointSize); - - window.UpdateView(images, scene.images); - - glLineWidth(4); - glBegin(GL_LINES); - glColor3f(1.0, 0.0, 0.0); - glVertex3f(0.0, 0.0, 0.0); - glVertex3f(2, 0.0, 0.0); - glEnd(); - - glLineWidth(2); - glBegin(GL_LINES); - glColor3f(0.0, 1.0, 0.0); - glVertex3f(0.0, 0.0, 0.0); - glVertex3f(0.0, 2, 0.0); - glEnd(); - - glLineWidth(0.5); - glBegin(GL_LINES); - glColor3f(0.0, 0.0, 1.0); - glVertex3f(0.0, 0.0, 0.0); - glVertex3f(0.0, 0.0, 2); - glEnd(); - - // render point-cloud - if (listPointCloud) { - glDisable(GL_TEXTURE_2D); - glCallList(listPointCloud); - } - // render mesh - if (listMesh) { - glEnable(GL_DEPTH_TEST); - glEnable(GL_CULL_FACE); - if (!scene.mesh.faceTexcoords.IsEmpty() && window.bRenderTexture) { - glEnable(GL_TEXTURE_2D); - textures.First().Bind(); - glCallList(listMesh); - glDisable(GL_TEXTURE_2D); - } else { - glEnable(GL_LIGHTING); - glCallList(listMesh); - glDisable(GL_LIGHTING); - } - } - // render cameras - if (window.bRenderCameras) { - glDisable(GL_CULL_FACE); - FOREACH(idx, images) { - Image& image = images[idx]; - const MVS::Image& imageData = scene.images[image.idx]; - const MVS::Camera& camera = imageData.camera; - // change coordinates system to the camera space - glPushMatrix(); - glMultMatrixd((GLdouble*)TransL2W((const Matrix3x3::EMat)camera.R, -(const Point3::EVec)camera.C).data()); - glPointSize(window.pointSize+1.f); - glDisable(GL_TEXTURE_2D); - // draw camera position and image center - const double scaleFocal(window.camera->scaleF); - glBegin(GL_POINTS); - glColor3f(1,0,0); glVertex3f(0,0,0); // camera position - glColor3f(0,1,0); glVertex3f(0,0,(float)scaleFocal); // image center - glEnd(); - // cache image corner coordinates - const Point2d pp(camera.GetPrincipalPoint()); - const double focal(camera.GetFocalLength()/scaleFocal); - const double cx(-pp.x/focal); - const double cy(-pp.y/focal); - const double px((double)imageData.width/focal+cx); - const double py((double)imageData.height/focal+cy); - const Point3d ic1(cx, cy, scaleFocal); - const Point3d ic2(cx, py, scaleFocal); - const Point3d ic3(px, py, scaleFocal); - const Point3d ic4(px, cy, scaleFocal); - // draw image thumbnail - const bool bSelectedImage(idx == window.camera->currentCamID); - if (bSelectedImage) { - if (image.IsValid()) { - // render image - glEnable(GL_TEXTURE_2D); - image.Bind(); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_BLEND); - glDisable(GL_DEPTH_TEST); - glColor4f(1,1,1,window.cameraBlend); - glBegin(GL_QUADS); - glTexCoord2d(0,0); glVertex3dv(ic1.ptr()); - glTexCoord2d(0,1); glVertex3dv(ic2.ptr()); - glTexCoord2d(1,1); glVertex3dv(ic3.ptr()); - glTexCoord2d(1,0); glVertex3dv(ic4.ptr()); - glEnd(); - glDisable(GL_TEXTURE_2D); - glDisable(GL_BLEND); - glEnable(GL_DEPTH_TEST); - } else { - // start and wait to load the image - if (image.IsImageEmpty()) { - // start loading - image.SetImageLoading(); - events.AddEvent(new EVTLoadImage(this, idx, IMAGE_MAX_RESOLUTION)); - } else { - // check if the image is available and set it - image.TransferImage(); - } - } - } - // draw camera frame - glColor3f(bSelectedImage ? 0.f : 1.f, 1.f, 0.f); - glBegin(GL_LINES); - glVertex3d(0,0,0); glVertex3dv(ic1.ptr()); - glVertex3d(0,0,0); glVertex3dv(ic2.ptr()); - glVertex3d(0,0,0); glVertex3dv(ic3.ptr()); - glVertex3d(0,0,0); glVertex3dv(ic4.ptr()); - glVertex3dv(ic1.ptr()); glVertex3dv(ic2.ptr()); - glVertex3dv(ic2.ptr()); glVertex3dv(ic3.ptr()); - glVertex3dv(ic3.ptr()); glVertex3dv(ic4.ptr()); - glVertex3dv(ic4.ptr()); glVertex3dv(ic1.ptr()); - glEnd(); - // restore coordinate system - glPopMatrix(); - } - } - if (window.selectionType != Window::SEL_NA) { - glPointSize(window.pointSize+4); - glDisable(GL_DEPTH_TEST); - glBegin(GL_POINTS); - glColor3f(1,0,0); glVertex3fv(window.selectionPoints[0].ptr()); - if (window.selectionType == Window::SEL_TRIANGLE) { - glColor3f(0,1,0); glVertex3fv(window.selectionPoints[1].ptr()); - glColor3f(0,0,1); glVertex3fv(window.selectionPoints[2].ptr()); - } - glEnd(); - glEnable(GL_DEPTH_TEST); - glPointSize(window.pointSize); - } - glfwSwapBuffers(window.GetWindow()); -} - -void Scene::ProcessEvents() -{ - glfwWaitEvents(); - window.UpdateMousePosition(); - if (glfwGetMouseButton(window.GetWindow(), GLFW_MOUSE_BUTTON_1) != GLFW_RELEASE) - window.camera->Rotate(window.pos, window.prevPos); -} - -void Scene::Loop() -{ - while (!glfwWindowShouldClose(window.GetWindow())) { - ProcessEvents(); - Draw(); - } -} - - -void Scene::CastRay(const Ray3& ray, int action) -{ - if (!IsOctreeValid()) - return; - const double timeClick(0.2); - const double timeDblClick(0.3); - const double now(glfwGetTime()); - switch (action) { - case GLFW_PRESS: { - // remember when the click action started - window.selectionTimeClick = now; - break; } - case GLFW_RELEASE: { - if (now-window.selectionTimeClick > timeClick) { - // this is a long click, ignore it - break; - } else - if (window.selectionType != Window::SEL_NA && - now-window.selectionTime < timeDblClick) { - // this is a double click, center scene at the selected point - window.camera->center = Point3d(window.selectionPoints[3]); - window.camera->dist *= 0.7; - window.selectionTime = now; - } else - if (!octMesh.IsEmpty()) { - // find ray intersection with the mesh - const IntersectRayMesh intRay(octMesh, ray, scene.mesh); - if (intRay.pick.IsValid()) { - const MVS::Mesh::Face& face = scene.mesh.faces[(MVS::Mesh::FIndex)intRay.pick.idx]; - window.selectionPoints[0] = scene.mesh.vertices[face[0]]; - window.selectionPoints[1] = scene.mesh.vertices[face[1]]; - window.selectionPoints[2] = scene.mesh.vertices[face[2]]; - window.selectionPoints[3] = (ray.m_pOrig + ray.m_vDir*intRay.pick.dist).cast(); - window.selectionType = Window::SEL_TRIANGLE; - window.selectionTime = now; - DEBUG("Face selected:\n\tindex: %u\n\tvertex 1: %u (%g %g %g)\n\tvertex 2: %u (%g %g %g)\n\tvertex 3: %u (%g %g %g)", - intRay.pick.idx, - face[0], window.selectionPoints[0].x, window.selectionPoints[0].y, window.selectionPoints[0].z, - face[1], window.selectionPoints[1].x, window.selectionPoints[1].y, window.selectionPoints[1].z, - face[2], window.selectionPoints[2].x, window.selectionPoints[2].y, window.selectionPoints[2].z - ); - } else { - window.selectionType = Window::SEL_NA; - } - } else - if (!octPoints.IsEmpty()) { - // find ray intersection with the points - const IntersectRayPoints intRay(octPoints, ray, scene.pointcloud, window.minViews); - if (intRay.pick.IsValid()) { - window.selectionPoints[0] = window.selectionPoints[3] = scene.pointcloud.points[intRay.pick.idx]; - window.selectionType = Window::SEL_POINT; - window.selectionTime = now; - DEBUG("Point selected:\n\tindex: %u (%g %g %g)%s", - intRay.pick.idx, - window.selectionPoints[0].x, window.selectionPoints[0].y, window.selectionPoints[0].z, - [&]() { - if (scene.pointcloud.pointViews.empty()) - return String(); - const MVS::PointCloud::ViewArr& views = scene.pointcloud.pointViews[intRay.pick.idx]; - ASSERT(!views.empty()); - String strViews(String::FormatString("\n\tviews: %u", views.size())); - for (MVS::PointCloud::View idxImage: views) { - const MVS::Image& imageData = scene.images[idxImage]; - const Point2 x(imageData.camera.TransformPointW2I(Cast(window.selectionPoints[0]))); - strViews += String::FormatString("\n\t\t%s (%.2f %.2f)", Util::getFileNameExt(imageData.name).c_str(), x.x, x.y); - } - return strViews; - }().c_str() - ); - } else { - window.selectionType = Window::SEL_POINT; - } - } - break; } - } -} -/*----------------------------------------------------------------*/ diff --git a/MVSEngine/Scene.h b/MVSEngine/Scene.h deleted file mode 100644 index 0d31fa0..0000000 --- a/MVSEngine/Scene.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Scene.h - * - * Copyright (c) 2014-2015 SEACAVE - * - * Author(s): - * - * cDc - * - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * - * Additional Terms: - * - * You are required to preserve legal notices and author attributions in - * that material or in the Appropriate Legal Notices displayed by works - * containing it. - */ - -#ifndef _VIEWER_SCENE_H_ -#define _VIEWER_SCENE_H_ - - -// I N C L U D E S ///////////////////////////////////////////////// - -#include "Window.h" - - -// D E F I N E S /////////////////////////////////////////////////// - - -// S T R U C T S /////////////////////////////////////////////////// - -namespace VIEWER { - -class Scene -{ -public: - typedef TOctree OctreePoints; - typedef TOctree OctreeMesh; - -public: - String name; - - String sceneName; - MVS::Scene scene; - Window window; - ImageArr images; // scene photos - ImageArr textures; // mesh textures - - OctreePoints octPoints; - OctreeMesh octMesh; - - GLuint listPointCloud; - GLuint listMesh; - - // multi-threading - static SEACAVE::EventQueue events; // internal events queue (processed by the working threads) - static SEACAVE::Thread thread; // worker thread - -public: - Scene(); - ~Scene(); - - void Empty(); - void Release(); - void ReleasePointCloud(); - void ReleaseMesh(); - inline bool IsValid() const { return window.IsValid(); } - inline bool IsOpen() const { return IsValid() && !scene.IsEmpty(); } - inline bool IsOctreeValid() const { return !octPoints.IsEmpty() || !octMesh.IsEmpty(); } - - bool Init(int width, int height, LPCTSTR windowName, LPCTSTR fileName=NULL, LPCTSTR meshFileName=NULL); - bool Open(LPCTSTR fileName, LPCTSTR meshFileName=NULL); - bool Export(LPCTSTR fileName, LPCTSTR exportType=NULL, bool losslessTexture=false) const; - void CompilePointCloud(); - void CompileMesh(); - - void Draw(); - void ProcessEvents(); - void Loop(); - - void CastRay(const Ray3&, int); -protected: - static void* ThreadWorker(void*); -}; -/*----------------------------------------------------------------*/ - -} // namespace VIEWER - -#endif // _VIEWER_SCENE_H_ diff --git a/MVSEngine/SparseCloud.mvs b/MVSEngine/SparseCloud.mvs deleted file mode 100644 index 6ce7735..0000000 Binary files a/MVSEngine/SparseCloud.mvs and /dev/null differ diff --git a/MVSEngine/Viewer.cpp b/MVSEngine/Viewer.cpp deleted file mode 100644 index 3a6522a..0000000 --- a/MVSEngine/Viewer.cpp +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Viewer.cpp - * - * Copyright (c) 2014-2015 SEACAVE - * - * Author(s): - * - * cDc - * - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * - * Additional Terms: - * - * You are required to preserve legal notices and author attributions in - * that material or in the Appropriate Legal Notices displayed by works - * containing it. - */ - -#include "Common.h" -#include -#include "Scene.h" -#include "MVSEngine.h" - -using namespace VIEWER; -// D E F I N E S /////////////////////////////////////////////////// - -#define APPNAME _T("J3DViewer") - - -// S T R U C T S /////////////////////////////////////////////////// - -namespace OPT { -String strInputFileName; -String strOutputFileName; -String strMeshFileName; -bool bLosslessTexture; -unsigned nArchiveType; -int nProcessPriority; -unsigned nMaxThreads; -unsigned nMaxMemory; -String strExportType; -String strConfigFileName; -#if TD_VERBOSE != TD_VERBOSE_OFF -bool bLogFile; -#endif -boost::program_options::variables_map vm; -} // namespace OPT - -// initialize and parse the command line parameters -bool MVSEngine::Initialize_MVSViewer(size_t argc, LPCTSTR* argv) -{ - // initialize log and console - //OPEN_LOG(); - //OPEN_LOGCONSOLE(); - - // group of options allowed only on command line - boost::program_options::options_description generic("Generic options"); - generic.add_options() - ("help,h", "produce this help message") - ("working-folder,w", boost::program_options::value(&WORKING_FOLDER), "working directory (default current directory)") - ("config-file,c", boost::program_options::value(&OPT::strConfigFileName)->default_value(APPNAME _T(".cfg")), "file name containing program options") - ("export-type", boost::program_options::value(&OPT::strExportType), "file type used to export the 3D scene (ply or obj)") - ("archive-type", boost::program_options::value(&OPT::nArchiveType)->default_value(2), "project archive type: 0-text, 1-binary, 2-compressed binary") - ("process-priority", boost::program_options::value(&OPT::nProcessPriority)->default_value(0), "process priority (normal by default)") - ("max-threads", boost::program_options::value(&OPT::nMaxThreads)->default_value(0), "maximum number of threads that this process should use (0 - use all available cores)") - ("max-memory", boost::program_options::value(&OPT::nMaxMemory)->default_value(0), "maximum amount of memory in MB that this process should use (0 - use all available memory)") - #if TD_VERBOSE != TD_VERBOSE_OFF - ("log-file", boost::program_options::value(&OPT::bLogFile)->default_value(false), "dump log to a file") - ("verbosity,v", boost::program_options::value(&g_nVerbosityLevel)->default_value( - #if TD_VERBOSE == TD_VERBOSE_DEBUG - 3 - #else - 2 - #endif - ), "verbosity level") - #endif - ; - - // group of options allowed both on command line and in config file - boost::program_options::options_description config("Viewer options"); - config.add_options() - ("input-file,i", boost::program_options::value(&OPT::strInputFileName), "input project filename containing camera poses and scene (point-cloud/mesh)") - ("output-file,o", boost::program_options::value(&OPT::strOutputFileName), "output filename for storing the mesh") - ("texture-lossless", boost::program_options::value(&OPT::bLosslessTexture)->default_value(false), "export texture using a lossless image format") - ; - - // hidden options, allowed both on command line and - // in config file, but will not be shown to the user - boost::program_options::options_description hidden("Hidden options"); - hidden.add_options() - ("mesh-file", boost::program_options::value(&OPT::strMeshFileName), "mesh file name to texture (overwrite the existing mesh)") - ; - - boost::program_options::options_description cmdline_options; - cmdline_options.add(generic).add(config).add(hidden); - - boost::program_options::options_description config_file_options; - config_file_options.add(config).add(hidden); - - boost::program_options::positional_options_description p; - p.add("input-file", -1); - - try { - // parse command line options - boost::program_options::store(boost::program_options::command_line_parser((int)argc, argv).options(cmdline_options).positional(p).run(), OPT::vm); - boost::program_options::notify(OPT::vm); - INIT_WORKING_FOLDER; - // parse configuration file - std::ifstream ifs(MAKE_PATH_SAFE(OPT::strConfigFileName)); - if (ifs) { - boost::program_options::store(parse_config_file(ifs, config_file_options), OPT::vm); - boost::program_options::notify(OPT::vm); - } - } - catch (const std::exception& e) { - //LOG(e.what()); - return false; - } - - // print application details: version and command line - - // validate input - Util::ensureValidPath(OPT::strInputFileName); - - if (!OPT::strExportType.IsEmpty()) - OPT::strExportType = OPT::strExportType.ToLower() == _T("obj") ? _T(".obj") : _T(".ply"); - - // initialize optional options - Util::ensureValidPath(OPT::strOutputFileName); - Util::ensureValidPath(OPT::strMeshFileName); - - // initialize global options - Process::setCurrentProcessPriority((Process::Priority)OPT::nProcessPriority); - #ifdef _USE_OPENMP - if (OPT::nMaxThreads != 0) - omp_set_num_threads(OPT::nMaxThreads); - #endif - - #ifdef _USE_BREAKPAD - // start memory dumper - MiniDumper::Create(APPNAME, WORKING_FOLDER); - #endif - - Util::Init(); - return true; -} - - - -int MVSEngine::MVSViewer(int num, char* cmd[]) -{ - #ifdef _DEBUGINFO - // set _crtBreakAlloc index to stop in at allocation - _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);// | _CRTDBG_CHECK_ALWAYS_DF); - #endif - - int argc = num; - LPCTSTR* argv = (LPCTSTR*)cmd; - if (!Initialize_MVSViewer(argc, argv)) - return EXIT_FAILURE; - - // create viewer - Scene viewer; - if (!viewer.Init(960, 540, APPNAME, - OPT::strInputFileName.IsEmpty() ? NULL : MAKE_PATH_SAFE(OPT::strInputFileName).c_str(), - OPT::strMeshFileName.IsEmpty() ? NULL : MAKE_PATH_SAFE(OPT::strMeshFileName).c_str())) - return EXIT_FAILURE; - if (viewer.IsOpen() && !OPT::strOutputFileName.IsEmpty()) { - // export the scene - viewer.Export(MAKE_PATH_SAFE(OPT::strOutputFileName), OPT::strExportType.IsEmpty()?LPCTSTR(NULL):OPT::strExportType.c_str(), OPT::bLosslessTexture); - } - // enter viewer loop - viewer.Loop(); - - return EXIT_SUCCESS; -} -/*----------------------------------------------------------------*/ diff --git a/MVSEngine/Window.cpp b/MVSEngine/Window.cpp deleted file mode 100644 index 4cb3eee..0000000 --- a/MVSEngine/Window.cpp +++ /dev/null @@ -1,354 +0,0 @@ -/* - * Window.cpp - * - * Copyright (c) 2014-2015 SEACAVE - * - * Author(s): - * - * cDc - * - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * - * Additional Terms: - * - * You are required to preserve legal notices and author attributions in - * that material or in the Appropriate Legal Notices displayed by works - * containing it. - */ - -#include "Common.h" -#include "Window.h" - -using namespace VIEWER; - - -// D E F I N E S /////////////////////////////////////////////////// - - -// S T R U C T S /////////////////////////////////////////////////// - -Window::WindowsMap Window::g_mapWindows; - -Window::Window() - : - window(NULL), - pos(Eigen::Vector2d::Zero()), - prevPos(Eigen::Vector2d::Zero()) -{ -} -Window::~Window() -{ - Release(); -} - -void Window::Release() -{ - if (IsValid()) { - glfwDestroyWindow(window); - window = NULL; - } - clbkOpenScene.reset(); - clbkExportScene.reset(); - clbkRayScene.reset(); - clbkCompilePointCloud.reset(); - clbkCompileMesh.reset(); -} - -bool Window::Init(int width, int height, LPCTSTR name) -{ - glfwDefaultWindowHints(); - glfwWindowHint(GLFW_VISIBLE, 0); - window = glfwCreateWindow(width, height, name, NULL, NULL); - if (!window) - return false; - glfwMakeContextCurrent(window); - glfwSetFramebufferSizeCallback(window, Window::Resize); - glfwSetKeyCallback(window, Window::Key); - glfwSetMouseButtonCallback(window, Window::MouseButton); - glfwSetScrollCallback(window, Window::Scroll); - glfwSetDropCallback(window, Window::Drop); - g_mapWindows[window] = this; - Reset(); - return true; -} -void Window::SetCamera(CameraPtr cam) -{ - camera = cam; - int width, height; - glfwGetWindowSize(window, &width, &height); - Resize(width, height); -} -void Window::SetName(LPCTSTR name) -{ - glfwSetWindowTitle(window, name); -} -void Window::SetVisible(bool v) -{ - if (v) - glfwShowWindow(window); - else - glfwHideWindow(window); -} -void Window::Reset(uint32_t _minViews) -{ - if (camera) - camera->Reset(); - sparseType = SPR_ALL; - minViews = _minViews; - pointSize = 2.f; - cameraBlend = 0.5f; - bRenderCameras = true; - bRenderSolid = true; - bRenderTexture = true; - selectionType = SEL_NA; - if (clbkCompilePointCloud != NULL) - clbkCompilePointCloud(); - if (clbkCompileMesh != NULL) - clbkCompileMesh(); - glfwPostEmptyEvent(); -} - -void Window::UpdateView(const ImageArr& images, const MVS::ImageArr& sceneImages) -{ - glMatrixMode(GL_MODELVIEW); - if (camera->prevCamID != camera->currentCamID && camera->currentCamID != NO_ID) { - // enable camera view mode - // apply current camera transform - const Image& image = images[camera->currentCamID]; - const MVS::Image& imageData = sceneImages[image.idx]; - const MVS::Camera& camera = imageData.camera; - const Eigen::Matrix4d trans(TransW2L((const Matrix3x3::EMat)camera.R, camera.GetT())); - glLoadMatrixf((GLfloat*)gs_convert); - glMultMatrixd((GLdouble*)trans.data()); - } else { - // apply view point transform - const Eigen::Matrix4d trans(camera->GetLookAt()); - glLoadMatrixd((GLdouble*)trans.data()); - } -} - -void Window::UpdateMousePosition() -{ - prevPos = pos; - // get current position - glfwGetCursorPos(window, &pos.x(), &pos.y()); - // normalize position to [-1:1] range - const int w(camera->width); - const int h(camera->height); - pos.x() = (2.0 * pos.x() - w) / w; - pos.y() = (h - 2.0 * pos.y()) / h; -} - -void Window::Resize(int width, int height) -{ - glfwMakeContextCurrent(window); - glViewport(0, 0, (GLint)width, (GLint)height); - camera->Resize(width, height); -} -void Window::Resize(GLFWwindow* window, int width, int height) -{ - g_mapWindows[window]->Resize(width, height); -} - -void Window::Key(int k, int /*scancode*/, int action, int mod) -{ - switch (k) { - case GLFW_KEY_ESCAPE: - if (action == GLFW_RELEASE) - glfwSetWindowShouldClose(window, 1); - break; - case GLFW_KEY_DOWN: - if (action == GLFW_RELEASE) { - if (mod & GLFW_MOD_SHIFT) { - if (minViews > 2) { - minViews--; - if (clbkCompilePointCloud != NULL) - clbkCompilePointCloud(); - } - } else { - pointSize = MAXF(pointSize-0.5f, 0.5f); - } - } - break; - case GLFW_KEY_UP: - if (action == GLFW_RELEASE) { - if (mod & GLFW_MOD_SHIFT) { - minViews++; - if (clbkCompilePointCloud != NULL) - clbkCompilePointCloud(); - } else { - pointSize += 0.5f; - } - } - break; - case GLFW_KEY_LEFT: - if (action != GLFW_RELEASE) { - camera->prevCamID = camera->currentCamID; - camera->currentCamID--; - if (camera->currentCamID < NO_ID && camera->currentCamID >= camera->maxCamID) - camera->currentCamID = camera->maxCamID-1; - } - break; - case GLFW_KEY_RIGHT: - if (action != GLFW_RELEASE) { - camera->prevCamID = camera->currentCamID; - camera->currentCamID++; - if (camera->currentCamID >= camera->maxCamID) - camera->currentCamID = NO_ID; - } - break; - case GLFW_KEY_E: - if (action == GLFW_RELEASE && clbkExportScene != NULL) - clbkExportScene(NULL, NULL, false); - break; - case GLFW_KEY_R: - if (action == GLFW_RELEASE) - Reset(); - break; - case GLFW_KEY_C: - if (action == GLFW_RELEASE) - bRenderCameras = !bRenderCameras; - break; - case GLFW_KEY_W: - if (action == GLFW_RELEASE) { - if (bRenderSolid) { - bRenderSolid = false; - glPolygonMode(GL_FRONT, GL_LINE); - } else { - bRenderSolid = true; - glPolygonMode(GL_FRONT, GL_FILL); - } - } - break; - case GLFW_KEY_T: - if (action == GLFW_RELEASE) { - bRenderTexture = !bRenderTexture; - if (clbkCompileMesh != NULL) - clbkCompileMesh(); - } - break; - case GLFW_KEY_P: - switch (sparseType) { - case SPR_POINTS: sparseType = SPR_LINES; break; - case SPR_LINES: sparseType = SPR_ALL; break; - case SPR_ALL: sparseType = SPR_POINTS; break; - } - if (clbkCompilePointCloud != NULL) - clbkCompilePointCloud(); - break; - case GLFW_KEY_KP_SUBTRACT: - if (action == GLFW_RELEASE) { - if (mod & GLFW_MOD_CONTROL) - camera->SetFOV(MAXF(camera->fov-5, 5.0)); - else if (mod & GLFW_MOD_SHIFT) - camera->scaleF *= 0.9f; - else - cameraBlend = MAXF(cameraBlend-0.1f, 0.f); - } - break; - case GLFW_KEY_KP_ADD: - if (action == GLFW_RELEASE) { - if (mod & GLFW_MOD_CONTROL) - camera->SetFOV(camera->fov+5); - else if (mod & GLFW_MOD_SHIFT) - camera->scaleF *= 1.11f; - else - cameraBlend = MINF(cameraBlend+0.1f, 1.f); - } - break; - } -} -void Window::Key(GLFWwindow* window, int k, int scancode, int action, int mod) -{ - g_mapWindows[window]->Key(k, scancode, action, mod); -} - -void Window::MouseButton(int button, int action, int /*mods*/) -{ - if (clbkRayScene != NULL && button == GLFW_MOUSE_BUTTON_LEFT) { - typedef Eigen::Matrix Mat4; - Mat4 P, V; - glGetDoublev(GL_MODELVIEW_MATRIX, V.data()); - glGetDoublev(GL_PROJECTION_MATRIX, P.data()); - // 4d Homogeneous Clip Coordinates - const Eigen::Vector4d ray_clip(pos.x(), pos.y(), -1.0, 1.0); - // 4d Eye (Camera) Coordinates - Eigen::Vector4d ray_eye(P.inverse()*ray_clip); - ray_eye.z() = -1.0; - ray_eye.w() = 0.0; - // 4d World Coordinates - const Mat4 invV(V.inverse()); - ASSERT(ISEQUAL(invV(3,3),1.0)); - const Eigen::Vector3d start(invV.topRightCorner<3,1>()); - const Eigen::Vector4d ray_wor(invV*ray_eye); - const Eigen::Vector3d dir(ray_wor.topRows<3>().normalized()); - clbkRayScene(Ray3d(start, dir), action); - } -} -void Window::MouseButton(GLFWwindow* window, int button, int action, int mods) -{ - g_mapWindows[window]->MouseButton(button, action, mods); -} - -void Window::Scroll(double /*xoffset*/, double yoffset) -{ - camera->dist *= (yoffset>0 ? POW(1.11,yoffset) : POW(0.9,-yoffset)); -} -void Window::Scroll(GLFWwindow* window, double xoffset, double yoffset) -{ - g_mapWindows[window]->Scroll(xoffset, yoffset); -} - -void Window::Drop(int count, const char** paths) -{ - if (clbkOpenScene && count > 0) { - SetVisible(false); - String fileName(paths[0]); - Util::ensureUnifySlash(fileName); - if (count > 1) { - String meshFileName(paths[1]); - Util::ensureUnifySlash(meshFileName); - clbkOpenScene(fileName, meshFileName); - } else { - clbkOpenScene(fileName, NULL); - } - SetVisible(true); - } -} -void Window::Drop(GLFWwindow* window, int count, const char** paths) -{ - g_mapWindows[window]->Drop(count, paths); -} - -bool Window::IsShiftKeyPressed() const -{ - return - glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || - glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS; -} -bool Window::IsCtrlKeyPressed() const -{ - return - glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS || - glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS; -} -bool Window::IsAltKeyPressed() const -{ - return - glfwGetKey(window, GLFW_KEY_LEFT_ALT) == GLFW_PRESS || - glfwGetKey(window, GLFW_KEY_RIGHT_ALT) == GLFW_PRESS; -} -/*----------------------------------------------------------------*/ diff --git a/MVSEngine/Window.h b/MVSEngine/Window.h deleted file mode 100644 index 0d9fe50..0000000 --- a/MVSEngine/Window.h +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Window.h - * - * Copyright (c) 2014-2015 SEACAVE - * - * Author(s): - * - * cDc - * - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * - * Additional Terms: - * - * You are required to preserve legal notices and author attributions in - * that material or in the Appropriate Legal Notices displayed by works - * containing it. - */ - -#ifndef _VIEWER_WINDOW_H_ -#define _VIEWER_WINDOW_H_ - - -// I N C L U D E S ///////////////////////////////////////////////// - -#include "Camera.h" -#include "Image.h" - - -// D E F I N E S /////////////////////////////////////////////////// - - -// S T R U C T S /////////////////////////////////////////////////// - -namespace VIEWER { - -class Window -{ -public: - GLFWwindow* window; // window handle - CameraPtr camera; // current camera (always valid) - Eigen::Vector2d pos, prevPos; // current and previous mouse position (normalized) - - enum SPARSE { - SPR_POINTS = (1 << 0), - SPR_LINES = (1 << 1), - SPR_ALL = SPR_POINTS|SPR_LINES - }; - SPARSE sparseType; - unsigned minViews; - float pointSize; - float cameraBlend; - bool bRenderCameras; - bool bRenderSolid; - bool bRenderTexture; - - enum SELECTION { - SEL_NA = 0, - SEL_POINT, - SEL_TRIANGLE - }; - SELECTION selectionType; - Point3f selectionPoints[4]; - double selectionTimeClick, selectionTime; - - typedef DELEGATE ClbkOpenScene; - ClbkOpenScene clbkOpenScene; - typedef DELEGATE ClbkExportScene; - ClbkExportScene clbkExportScene; - typedef DELEGATE ClbkRayScene; - ClbkRayScene clbkRayScene; - typedef DELEGATE ClbkCompilePointCloud; - ClbkCompilePointCloud clbkCompilePointCloud; - typedef DELEGATE ClbkCompileMesh; - ClbkCompileMesh clbkCompileMesh; - - typedef std::unordered_map WindowsMap; - static WindowsMap g_mapWindows; - -public: - Window(); - ~Window(); - - void Release(); - inline bool IsValid() const { return window != NULL; } - - bool Init(int width, int height, LPCTSTR name); - void SetCamera(CameraPtr); - void SetName(LPCTSTR); - void SetVisible(bool); - void Reset(uint32_t minViews=2); - - inline GLFWwindow* GetWindow() { return window; } - - void UpdateView(const ImageArr&, const MVS::ImageArr&); - void UpdateMousePosition(); - - void Resize(int width, int height); - static void Resize(GLFWwindow* window, int width, int height); - void Key(int k, int scancode, int action, int mod); - static void Key(GLFWwindow* window, int k, int scancode, int action, int mod); - void MouseButton(int button, int action, int mods); - static void MouseButton(GLFWwindow* window, int button, int action, int mods); - void Scroll(double xoffset, double yoffset); - static void Scroll(GLFWwindow* window, double xoffset, double yoffset); - void Drop(int count, const char** paths); - static void Drop(GLFWwindow* window, int count, const char** paths); - -protected: - bool IsShiftKeyPressed() const; - bool IsCtrlKeyPressed() const; - bool IsAltKeyPressed() const; -}; -/*----------------------------------------------------------------*/ - -} // namespace VIEWER - -#endif // _VIEWER_WINDOW_H_ diff --git a/MVSEngine/x64/Release/DensifyPointCloud.obj b/MVSEngine/x64/Release/DensifyPointCloud.obj index 18e663b..ccc4123 100644 Binary files a/MVSEngine/x64/Release/DensifyPointCloud.obj and b/MVSEngine/x64/Release/DensifyPointCloud.obj differ diff --git a/MVSEngine/x64/Release/J3DMVSEngine.Build.CppClean.log b/MVSEngine/x64/Release/J3DMVSEngine.Build.CppClean.log index aff5fc2..ba1f25c 100644 --- a/MVSEngine/x64/Release/J3DMVSEngine.Build.CppClean.log +++ b/MVSEngine/x64/Release/J3DMVSEngine.Build.CppClean.log @@ -1,20 +1,17 @@ e:\work\jwl3d\mvsengine\x64\release\vc141.pdb -e:\work\jwl3d\mvsengine\x64\release\window.obj -e:\work\jwl3d\mvsengine\x64\release\viewer.obj e:\work\jwl3d\mvsengine\x64\release\texturemesh.obj -e:\work\jwl3d\mvsengine\x64\release\scene.obj e:\work\jwl3d\mvsengine\x64\release\refinemesh.obj e:\work\jwl3d\mvsengine\x64\release\reconstructmesh.obj -e:\work\jwl3d\mvsengine\x64\release\image.obj e:\work\jwl3d\mvsengine\x64\release\densifypointcloud.obj -e:\work\jwl3d\mvsengine\x64\release\common.obj -e:\work\jwl3d\mvsengine\x64\release\camera.obj +e:\work\jwl3d\x64\release\j3dmvsengine.lib +e:\work\jwl3d\x64\release\j3dmvsengine.exp +e:\work\jwl3d\x64\release\j3dmvsengine.dll +e:\work\jwl3d\x64\release\j3dmvsengine.pdb e:\work\jwl3d\mvsengine\x64\release\j3dmvsengine.res e:\work\jwl3d\mvsengine\x64\release\j3dmvsengine.tlog\cl.command.1.tlog e:\work\jwl3d\mvsengine\x64\release\j3dmvsengine.tlog\cl.read.1.tlog e:\work\jwl3d\mvsengine\x64\release\j3dmvsengine.tlog\cl.write.1.tlog -e:\work\jwl3d\mvsengine\x64\release\j3dmvsengine.tlog\link.9528.read.1.tlog -e:\work\jwl3d\mvsengine\x64\release\j3dmvsengine.tlog\link.9528.write.1.tlog +e:\work\jwl3d\mvsengine\x64\release\j3dmvsengine.tlog\j3dmvsengine.write.1u.tlog e:\work\jwl3d\mvsengine\x64\release\j3dmvsengine.tlog\link.command.1.tlog e:\work\jwl3d\mvsengine\x64\release\j3dmvsengine.tlog\link.read.1.tlog e:\work\jwl3d\mvsengine\x64\release\j3dmvsengine.tlog\link.write.1.tlog diff --git a/MVSEngine/x64/Release/J3DMVSEngine.tlog/link.read.1.tlog b/MVSEngine/x64/Release/J3DMVSEngine.tlog/link.read.1.tlog index 8d74118..af8625a 100644 Binary files a/MVSEngine/x64/Release/J3DMVSEngine.tlog/link.read.1.tlog and b/MVSEngine/x64/Release/J3DMVSEngine.tlog/link.read.1.tlog differ diff --git a/MVSEngine/x64/Release/MVSEngine.log b/MVSEngine/x64/Release/MVSEngine.log index c0a4a0a..ba89907 100644 --- a/MVSEngine/x64/Release/MVSEngine.log +++ b/MVSEngine/x64/Release/MVSEngine.log @@ -1,5 +1,4 @@ -锘緾:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppClean.targets(76,5): warning : 鏂囦欢鈥渆:\work\jwl3d\mvsengine\x64\release\vc141.pdb鈥濇鐢卞彟涓杩涚▼浣跨敤锛屽洜姝よ杩涚▼鏃犳硶璁块棶姝ゆ枃浠躲 - DensifyPointCloud.cpp +锘 DensifyPointCloud.cpp c:\openmvs\src\libs\common\types.inl(2508): warning C4819: 璇ユ枃浠跺寘鍚笉鑳藉湪褰撳墠浠g爜椤(936)涓〃绀虹殑瀛楃銆傝灏嗚鏂囦欢淇濆瓨涓 Unicode 鏍煎紡浠ラ槻姝㈡暟鎹涪澶 c:\openmvs\boost\boost_1_67_0\boost\iostreams\positioning.hpp(96): warning C4996: 'std::fpos<_Mbstatet>::seekpos': warning STL4019: The member std::fpos::seekpos() is non-Standard, and is preserved only for compatibility with workarounds for old versions of Visual C++. It will be removed in a future release, and in this release always returns 0. Please use standards-conforming mechanisms to manipulate fpos, such as conversions to and from streamoff, or an integral type, instead. If you are receiving this message while compiling Boost.IOStreams, a fix has been submitted upstream to make Boost use standards-conforming mechanisms, as it does for other compilers. You can define _SILENCE_FPOS_SEEKPOS_DEPRECATION_WARNING to acknowledge that you have received this warning, or define _REMOVE_FPOS_SEEKPOS to remove std::fpos::seekpos entirely. c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\iosfwd(59): note: 鍙傝鈥渟td::fpos<_Mbstatet>::seekpos鈥濈殑澹版槑 diff --git a/MVSEngine/x64/Release/ReconstructMesh.obj b/MVSEngine/x64/Release/ReconstructMesh.obj index 5d3aa5f..c02cfd6 100644 Binary files a/MVSEngine/x64/Release/ReconstructMesh.obj and b/MVSEngine/x64/Release/ReconstructMesh.obj differ diff --git a/MVSEngine/x64/Release/RefineMesh.obj b/MVSEngine/x64/Release/RefineMesh.obj index 5013b57..4c3dccf 100644 Binary files a/MVSEngine/x64/Release/RefineMesh.obj and b/MVSEngine/x64/Release/RefineMesh.obj differ diff --git a/MVSEngine/x64/Release/TextureMesh.obj b/MVSEngine/x64/Release/TextureMesh.obj index af65f9d..b89044d 100644 Binary files a/MVSEngine/x64/Release/TextureMesh.obj and b/MVSEngine/x64/Release/TextureMesh.obj differ diff --git a/MVSEngine/x64/Release/vc141.pdb b/MVSEngine/x64/Release/vc141.pdb index 026e6eb..d59c123 100644 Binary files a/MVSEngine/x64/Release/vc141.pdb and b/MVSEngine/x64/Release/vc141.pdb differ