Skip to content

Commit

Permalink
Version 0.9.5, 27.01.2018
Browse files Browse the repository at this point in the history
Version 0.9.5, 27.01.2018:
- Path of user camera db can be set in properties
- Fixed bug: Now Brown camera model can be used
- New export to external MVS SURE (commercial tool by nFrames)
  • Loading branch information
rhiestan committed Jan 27, 2018
1 parent 0bc71c3 commit 54c737c
Show file tree
Hide file tree
Showing 14 changed files with 423 additions and 15 deletions.
91 changes: 82 additions & 9 deletions src/R3DModelOperations.cpp
Expand Up @@ -376,22 +376,22 @@ bool R3DModelOperations::exportSurface(R3DProject::Surface *pSurface, const wxSt
{
if(exportFN.GetExt().IsSameAs(wxT("obj")))
{
// Currently disabled due to bug 1315 of AssImp
// See also https://github.com/assimp/assimp/issues/1315
return false;

// Convert to Alias Wavefront Object
if(pSurface->colorizationType_ == R3DProject::CTColoredVertices)
{
const aiScene* pScene = imp.ReadFile(surfaceModelFNStr.c_str(), 0);
// Don't use AssImp to generate OBJ, but our own method

/*const aiScene* pScene = imp.ReadFile(surfaceModelFNStr.c_str(),
0);
if(pScene == NULL)
retVal = false;
else
{
std::string tmpfn("tmp/temp_surface.obj");
const aiReturn res = exp.Export(pScene, "obj", tmpfn.c_str());
const aiReturn res = exp.Export(pScene, "objnomtl", tmpfn.c_str());
retVal &= wxCopyFile(wxString(tmpfn.c_str(), wxConvLibc), filename, true);
}
}*/
convertSurfacePLYToOBJ(surfaceModelFN.GetFullPath(), filename);
}
else
{
Expand All @@ -411,7 +411,8 @@ bool R3DModelOperations::exportSurface(R3DProject::Surface *pSurface, const wxSt
{
if(pSurface->colorizationType_ == R3DProject::CTColoredVertices)
{
const aiScene* pScene = imp.ReadFile(surfaceModelFNStr.c_str(), aiProcess_JoinIdenticalVertices);
const aiScene* pScene = imp.ReadFile(surfaceModelFNStr.c_str(),
0);
if(pScene == NULL)
retVal = false;
else
Expand All @@ -429,7 +430,8 @@ bool R3DModelOperations::exportSurface(R3DProject::Surface *pSurface, const wxSt
else
{
// Load and save OBJ
const aiScene* pScene = imp.ReadFile(surfaceModelFNStr.c_str(), aiProcess_JoinIdenticalVertices);
const aiScene* pScene = imp.ReadFile(surfaceModelFNStr.c_str(),
0);
if(pScene == NULL)
retVal = false;
else
Expand Down Expand Up @@ -516,3 +518,74 @@ bool R3DModelOperations::exportSurface(R3DProject::Surface *pSurface, const wxSt

return retVal;
}

/**
* The OBJ file generated by AssImp is not accepted by MeshLab - for whatever reason.
*
* Use AssImp to load the PLY file and write the OBJ here.
*/
void R3DModelOperations::convertSurfacePLYToOBJ(const wxString &plyFilename, const wxString &objFilename)
{
#if defined(R3D_WIN32)
boost::filesystem::ofstream ostream(boost::filesystem::path(objFilename.wc_str()), std::ios::binary);
#else
boost::filesystem::ofstream ostream(boost::filesystem::path(objFilename.mb_str()), std::ios::binary);
#endif

ostream << "# File generated by Regard3D" << std::endl << std::endl;

Assimp::Importer imp;
std::string plyFilenameStr(plyFilename.mb_str());

const aiScene* pScene = imp.ReadFile(plyFilenameStr.c_str(),
aiProcess_JoinIdenticalVertices
| aiProcess_GenSmoothNormals);
if(pScene == NULL)
return;

for(int i = 0; i < pScene->mNumMeshes; i++)
{
auto *pMesh = pScene->mMeshes[i];
bool hasColor = false;
if(pMesh->GetNumColorChannels() > 0
&& pMesh->HasVertexColors(0))
hasColor = true;
aiColor4D *pColors = NULL;
if(hasColor)
pColors = pMesh->mColors[0];
for(int j = 0; j < pMesh->mNumVertices; j++)
{
auto v = pMesh->mVertices[j];
if(hasColor)
{
const aiColor4D &color = pColors[j];
ostream << "v " << v.x << " " << v.y << " " << v.z << " " << color.r << " " << color.g << " " << color.b << std::endl;
}
else
{
ostream << "v " << v.x << " " << v.y << " " << v.z << std::endl;
}

if(pMesh->HasNormals())
{
const auto vn = pMesh->mNormals[j];
ostream << "vn " << vn.x << " " << vn.y << " " << vn.z << std::endl;
}
}

for(int j = 0; j < pMesh->mNumFaces; j++)
{
auto face = pMesh->mFaces[j];
ostream << "f";
for(int k = 0; k < face.mNumIndices; k++)
{
auto index = face.mIndices[k];
index = index + 1; // OBJ-file requires one-based index
ostream << ' ' << index << "//" << index;
}
ostream << std::endl;
}
}

ostream << std::endl << "# End of File" << std::endl << std::endl;
}
2 changes: 2 additions & 0 deletions src/R3DModelOperations.h
Expand Up @@ -36,6 +36,8 @@ class R3DModelOperations

static bool exportSurface(R3DProject::Surface *pSurface, const wxString &filename);

static void convertSurfacePLYToOBJ(const wxString &plyFilename, const wxString &objFilename);

private:
R3DModelOperations() { }
virtual ~R3DModelOperations() { }
Expand Down
5 changes: 5 additions & 0 deletions src/R3DProject.cpp
Expand Up @@ -1080,6 +1080,7 @@ bool R3DProject::writeImageListTXT(const R3DProjectPaths &paths)
#include "openMVG/sfm/sfm_data_io.hpp"
#include "openMVG/cameras/Camera_Pinhole.hpp"
#include "openMVG/cameras/Camera_Pinhole_Radial.hpp"
#include "openMVG/cameras/Camera_Pinhole_Brown.hpp"
#include "openMVG/cameras/Camera_Pinhole_Fisheye.hpp"
#include "openMVG/cameras/Camera_IO.hpp"
#endif
Expand Down Expand Up @@ -1147,6 +1148,10 @@ bool R3DProject::writeSfmData(const R3DProjectPaths &paths, int cameraModel)
intrinsic = std::make_shared<openMVG::cameras::Pinhole_Intrinsic_Radial_K3>
(width, height, focal, ppx, ppy, 0.0, 0.0, 0.0); // setup no distortion as initial guess
break;
case openMVG::cameras::PINHOLE_CAMERA_BROWN:
intrinsic = std::make_shared<openMVG::cameras::Pinhole_Intrinsic_Brown_T2>
(width, height, focal, ppx, ppy, 0.0, 0.0, 0.0); // setup no distortion as initial guess
break;
case openMVG::cameras::PINHOLE_CAMERA_FISHEYE:
intrinsic = std::make_shared<openMVG::cameras::Pinhole_Intrinsic_Fisheye>
(width, height, focal, ppx, ppy, 0.0, 0.0, 0.0); // setup no distortion as initial guess
Expand Down
15 changes: 15 additions & 0 deletions src/Regard3DMainFrame.cpp
Expand Up @@ -54,6 +54,7 @@
#include "Regard3DPropertiesDialog.h"
#include "Regard3DUserCameraDBDialog.h"
#include "cpuinfo.hpp"
#include "UserCameraDB.h"

// wxWidgets
#include <wx/mstream.h>
Expand Down Expand Up @@ -433,6 +434,8 @@ void Regard3DMainFrame::OnMainFrameExitMenuItem( wxCommandEvent& WXUNUSED(event)
void Regard3DMainFrame::OnPropertiesMenuItem( wxCommandEvent& event )
{
wxString defaultProjectPath = Regard3DSettings::getInstance().getDefaultProjectPath();
wxFileName userCameraDBFN(Regard3DSettings::getInstance().getUserCameraDBFilename());
wxString userCameraDBPath = userCameraDBFN.GetPath();
if(defaultProjectPath.IsEmpty())
#if wxCHECK_VERSION(2, 9, 0)
defaultProjectPath = wxStandardPaths::Get().GetAppDocumentsDir();
Expand All @@ -443,21 +446,33 @@ void Regard3DMainFrame::OnPropertiesMenuItem( wxCommandEvent& event )
defaultProjectPath = dpp.GetPath(wxPATH_GET_VOLUME);
}
#endif
if(userCameraDBPath.IsEmpty())
{
wxString userLocalDataDir = wxStandardPaths::Get().GetUserLocalDataDir();
userCameraDBPath = userLocalDataDir;
}
int mouseButtonType = (Regard3DSettings::getInstance().getIsMouseButtonSwitched() ? 1 : 0);
int mouseWheelType = (Regard3DSettings::getInstance().getIsMouseWheelSwitched() ? 1 : 0);

Regard3DPropertiesDialog dlg(this);
dlg.pDefaultProjectPathDirPicker_->SetPath(defaultProjectPath);
dlg.pUserCameraDBLocationDirPicker_->SetPath(userCameraDBPath);
dlg.pMouseButtonRadioBox_->SetSelection(mouseButtonType);
dlg.pMouseWheelRadioBox_->SetSelection(mouseWheelType);

int retVal = dlg.ShowModal();
if(retVal == wxID_OK)
{
defaultProjectPath = dlg.pDefaultProjectPathDirPicker_->GetPath();
wxFileName userCameraDBFNNew(dlg.pUserCameraDBLocationDirPicker_->GetPath(), wxT("usercamera.db"));
mouseButtonType = dlg.pMouseButtonRadioBox_->GetSelection();
mouseWheelType = dlg.pMouseWheelRadioBox_->GetSelection();
Regard3DSettings::getInstance().setDefaultProjectPath(defaultProjectPath);
if(!userCameraDBFN.SameAs(userCameraDBFNNew))
{
Regard3DSettings::getInstance().setUserCameraDBFilename(userCameraDBFNNew.GetFullPath());
UserCameraDB::getInstance().initialize();
}
bool isMouseButtonSwitched = (mouseButtonType == 1);
Regard3DSettings::getInstance().setIsMouseButtonSwitched( isMouseButtonSwitched );
pOSGGLCanvas_->setIsMouseButtonSwitched(isMouseButtonSwitched);
Expand Down
8 changes: 8 additions & 0 deletions src/Regard3DMainFrameBase.cpp
Expand Up @@ -1928,6 +1928,14 @@ Regard3DPropertiesDialogBase::Regard3DPropertiesDialogBase( wxWindow* parent, wx

bSizer55->Add( sbSizer23, 0, wxALL|wxEXPAND, 3 );

wxStaticBoxSizer* sbSizer25;
sbSizer25 = new wxStaticBoxSizer( new wxStaticBox( pPopertiesPanel_, wxID_ANY, wxT("User camera DB location") ), wxVERTICAL );

pUserCameraDBLocationDirPicker_ = new wxDirPickerCtrl( pPopertiesPanel_, ID_USERCAMERADBLOCATIONDIRPICKER, wxEmptyString, wxT("Select a user camera DB location"), wxDefaultPosition, wxDefaultSize, wxDIRP_DEFAULT_STYLE|wxDIRP_DIR_MUST_EXIST|wxDIRP_USE_TEXTCTRL );
sbSizer25->Add( pUserCameraDBLocationDirPicker_, 0, wxALL|wxEXPAND, 3 );

bSizer55->Add( sbSizer25, 1, wxALL|wxEXPAND, 3 );

wxString pMouseButtonRadioBox_Choices[] = { wxT("Middle mouse button: Zoom, Right mouse button: Move"), wxT("Middle mouse button: Move, Right mouse button: Zoom") };
int pMouseButtonRadioBox_NChoices = sizeof( pMouseButtonRadioBox_Choices ) / sizeof( wxString );
pMouseButtonRadioBox_ = new wxRadioBox( pPopertiesPanel_, ID_MOUSEBUTTONRADIOBOX, wxT("Mouse button assignment"), wxDefaultPosition, wxDefaultSize, pMouseButtonRadioBox_NChoices, pMouseButtonRadioBox_Choices, 1, wxRA_SPECIFY_COLS );
Expand Down
2 changes: 2 additions & 0 deletions src/Regard3DMainFrameBase.h
Expand Up @@ -1165,6 +1165,7 @@ class Regard3DPropertiesDialogBase : public wxDialog
ID_REGARD3DPROPERTIESDIALOG = 1000,
ID_POPERTIESPANEL,
ID_DEFAULTPROJECTPATHDIRPICKER,
ID_USERCAMERADBLOCATIONDIRPICKER,
ID_MOUSEBUTTONRADIOBOX,
ID_MOUSEWHEELRADIOBOX,
};
Expand All @@ -1181,6 +1182,7 @@ class Regard3DPropertiesDialogBase : public wxDialog

public:
wxDirPickerCtrl* pDefaultProjectPathDirPicker_;
wxDirPickerCtrl* pUserCameraDBLocationDirPicker_;
wxRadioBox* pMouseButtonRadioBox_;
wxRadioBox* pMouseWheelRadioBox_;

Expand Down
71 changes: 71 additions & 0 deletions src/res/Regard3dMainFrameBase.fbp
Expand Up @@ -17414,6 +17414,77 @@
</object>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">3</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxStaticBoxSizer" expanded="1">
<property name="id">wxID_ANY</property>
<property name="label">User camera DB location</property>
<property name="minimum_size"></property>
<property name="name">sbSizer25</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<event name="OnUpdateUI"></event>
<object class="sizeritem" expanded="1">
<property name="border">3</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxDirPickerCtrl" expanded="1">
<property name="bg"></property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="font"></property>
<property name="hidden">0</property>
<property name="id">ID_USERCAMERADBLOCATIONDIRPICKER</property>
<property name="maximum_size"></property>
<property name="message">Select a user camera DB location</property>
<property name="minimum_size"></property>
<property name="name">pUserCameraDBLocationDirPicker_</property>
<property name="permission">public</property>
<property name="pos"></property>
<property name="size"></property>
<property name="style">wxDIRP_DEFAULT_STYLE|wxDIRP_DIR_MUST_EXIST|wxDIRP_USE_TEXTCTRL</property>
<property name="subclass"></property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="value"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnChar"></event>
<event name="OnDirChanged"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
</object>
</object>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">3</property>
<property name="flag">wxALL|wxEXPAND</property>
Expand Down

0 comments on commit 54c737c

Please sign in to comment.