From b2a1a450a12056a4360bc0540106394292f82449 Mon Sep 17 00:00:00 2001 From: cdcseacave Date: Sun, 11 Oct 2015 18:21:51 +0300 Subject: [PATCH] dense: add a stricter depth-map filter --- CMakeLists.txt | 4 +- build/Cotire.cmake | 66 ++++----- libs/Common/AutoEstimator.h | 6 +- libs/Common/AutoPtr.h | 14 +- libs/Common/CUDA.h | 12 +- libs/Common/CriticalSection.h | 16 +- libs/Common/EventQueue.h | 4 +- libs/Common/List.h | 160 +++++++++++++++++++- libs/Common/Log.h | 8 +- libs/Common/Octree.h | 8 +- libs/Common/SharedPtr.h | 4 +- libs/Common/Thread.h | 6 +- libs/Common/Timer.h | 6 +- libs/Common/Types.h | 117 ++++++++++----- libs/Common/Types.inl | 8 +- libs/Common/Util.cpp | 271 ---------------------------------- libs/Common/Util.h | 39 +---- libs/IO/OBJ.h | 2 +- libs/IO/PLY.h | 6 +- libs/MVS/DepthMap.cpp | 3 +- libs/MVS/DepthMap.h | 2 +- libs/MVS/Mesh.h | 4 +- libs/MVS/RectsBinPack.h | 6 +- libs/MVS/SceneDensify.cpp | 237 +++++++++++++++++++---------- libs/MVS/SceneReconstruct.cpp | 4 +- libs/MVS/SceneRefine.cpp | 4 +- libs/MVS/SceneTexture.cpp | 2 +- libs/Math/LBP.h | 2 +- 28 files changed, 495 insertions(+), 526 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 99e34a164..0cd3ff0a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,7 +73,7 @@ if(OpenMVS_USE_BREAKPAD) FIND_PACKAGE(BREAKPAD) if(BREAKPAD_FOUND) include_directories(${BREAKPAD_INCLUDE_DIRS}) - add_definitions(-D_USE_BREAKPAD) + add_definitions(${BREAKPAD_DEFINITIONS} -D_USE_BREAKPAD) else() message("-- Can't find BreakPad. Continuing without it.") endif() @@ -89,7 +89,7 @@ endif() FIND_PACKAGE(Eigen ${SYSTEM_PACKAGE_REQUIRED}) if(EIGEN_FOUND) include_directories(${EIGEN_INCLUDE_DIRS}) - add_definitions(${EIGEN_DEFINITIONS}) + add_definitions(${EIGEN_DEFINITIONS} -D_USE_EIGEN) endif() FIND_PACKAGE(OpenCV ${SYSTEM_PACKAGE_REQUIRED}) diff --git a/build/Cotire.cmake b/build/Cotire.cmake index 69e9a67ac..698636d68 100644 --- a/build/Cotire.cmake +++ b/build/Cotire.cmake @@ -42,6 +42,9 @@ if (NOT CMAKE_SCRIPT_MODE_FILE) cmake_policy(POP) endif() +set (COTIRE_CMAKE_MODULE_FILE "${CMAKE_CURRENT_LIST_FILE}") +set (COTIRE_CMAKE_MODULE_VERSION "1.7.4") + # activate select policies if (POLICY CMP0038) # targets may not link directly to themselves @@ -93,9 +96,6 @@ if (POLICY CMP0054) cmake_policy(SET CMP0054 NEW) endif() -set (COTIRE_CMAKE_MODULE_FILE "${CMAKE_CURRENT_LIST_FILE}") -set (COTIRE_CMAKE_MODULE_VERSION "1.7.3") - include(CMakeParseArguments) include(ProcessorCount) @@ -802,7 +802,7 @@ macro (cotire_add_frameworks_to_cmd _cmdVar _language) set (_frameWorkDirs "") foreach (_include ${ARGN}) if (IS_ABSOLUTE "${_include}" AND _include MATCHES "\\.framework$") - get_filename_component(_frameWorkDir "${_include}" PATH) + get_filename_component(_frameWorkDir "${_include}" DIRECTORY) list (APPEND _frameWorkDirs "${_frameWorkDir}") endif() endforeach() @@ -1508,7 +1508,7 @@ function (cotire_add_pch_compilation_flags _language _compilerID _compilerVersio # -Kc++ process all source or unrecognized file types as C++ source files # -fsyntax-only check only for correct syntax # -Wpch-messages enable diagnostics related to pre-compiled headers (requires Intel XE 2013 Update 2) - get_filename_component(_pchDir "${_pchFile}" PATH) + get_filename_component(_pchDir "${_pchFile}" DIRECTORY) get_filename_component(_pchName "${_pchFile}" NAME) set (_xLanguage_C "c-header") set (_xLanguage_CXX "c++-header") @@ -1634,7 +1634,7 @@ function (cotire_add_prefix_pch_inclusion_flags _language _compilerID _compilerV # -include process include file as the first line of the primary source file # -Wpch-messages enable diagnostics related to pre-compiled headers (requires Intel XE 2013 Update 2) if (_pchFile) - get_filename_component(_pchDir "${_pchFile}" PATH) + get_filename_component(_pchDir "${_pchFile}" DIRECTORY) get_filename_component(_pchName "${_pchFile}" NAME) if (_flags) # append to list @@ -2019,7 +2019,12 @@ function (cotire_generate_target_script _language _configurations _target _targe # copy variable definitions to cotire target script get_cmake_property(_vars VARIABLES) string (REGEX MATCHALL "COTIRE_[A-Za-z0-9_]+" _matchVars "${_vars}") - # remove COTIRE_VERBOSE which is passed as a CMake define on command line + # omit COTIRE_*_INIT variables + string (REGEX MATCHALL "COTIRE_[A-Za-z0-9_]+_INIT" _initVars "${_matchVars}") + if (_initVars) + list (REMOVE_ITEM _matchVars ${_initVars}) + endif() + # omit COTIRE_VERBOSE which is passed as a CMake define on command line list (REMOVE_ITEM _matchVars COTIRE_VERBOSE) set (_contents "") set (_contentsHasGeneratorExpressions FALSE) @@ -2298,21 +2303,15 @@ function (cotire_setup_unity_generation_commands _language _target _targetScript VERBATIM) list (APPEND ${_cmdsVar} COMMAND ${_unityCmd}) endforeach() - list (LENGTH _unityFiles _numberOfUnityFiles) - if (_numberOfUnityFiles GREATER 1) - # create a joint unity file from all unity file segments - cotire_make_single_unity_source_file_path(${_language} ${_target} _unityFile) - cotire_setup_combine_command(${_language} "${_targetConfigScript}" "${_unityFile}" ${_cmdsVar} ${_unityFiles}) - endif() set (${_cmdsVar} ${${_cmdsVar}} PARENT_SCOPE) endfunction() -function (cotire_setup_prefix_generation_command _language _target _targetScript _prefixFile _unityFile _cmdsVar) +function (cotire_setup_prefix_generation_command _language _target _targetScript _prefixFile _unityFiles _cmdsVar) set (_sourceFiles ${ARGN}) set (_dependencySources "") cotire_get_prefix_header_dependencies(${_language} ${_target} _dependencySources ${_sourceFiles}) cotire_set_cmd_to_prologue(_prefixCmd) - list (APPEND _prefixCmd -P "${COTIRE_CMAKE_MODULE_FILE}" "prefix" "${_targetScript}" "${_prefixFile}" "${_unityFile}") + list (APPEND _prefixCmd -P "${COTIRE_CMAKE_MODULE_FILE}" "prefix" "${_targetScript}" "${_prefixFile}" ${_unityFiles}) set_property (SOURCE "${_prefixFile}" PROPERTY GENERATED TRUE) if (COTIRE_DEBUG) message (STATUS "add_custom_command: OUTPUT ${_prefixFile} COMMAND ${_prefixCmd} DEPENDS ${_unityFile} ${_dependencySources}") @@ -2327,7 +2326,7 @@ function (cotire_setup_prefix_generation_command _language _target _targetScript add_custom_command( OUTPUT "${_prefixFile}" "${_prefixFile}.log" COMMAND ${_prefixCmd} - DEPENDS "${_unityFile}" ${_dependencySources} + DEPENDS ${_unityFiles} ${_dependencySources} COMMENT "${_comment}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" VERBATIM) @@ -2343,17 +2342,9 @@ function (cotire_setup_prefix_generation_from_unity_command _language _target _t else() set (_prefixSourceFile "${_prefixFile}") endif() - list (LENGTH _unityFiles _numberOfUnityFiles) - if (_numberOfUnityFiles GREATER 1) - cotire_make_single_unity_source_file_path(${_language} ${_target} _unityFile) - cotire_setup_prefix_generation_command( - ${_language} ${_target} "${_targetScript}" - "${_prefixSourceFile}" "${_unityFile}" ${_cmdsVar} ${_sourceFiles}) - else() - cotire_setup_prefix_generation_command( - ${_language} ${_target} "${_targetScript}" - "${_prefixSourceFile}" "${_unityFiles}" ${_cmdsVar} ${_sourceFiles}) - endif() + cotire_setup_prefix_generation_command( + ${_language} ${_target} "${_targetScript}" + "${_prefixSourceFile}" "${_unityFiles}" ${_cmdsVar} ${_sourceFiles}) if (CMAKE_${_language}_COMPILER_ID MATCHES "GNU|Clang") # set up generation of a prefix source file which includes the prefix header cotire_setup_combine_command(${_language} "${_targetScript}" "${_prefixFile}" _cmds ${_prefixSourceFile}) @@ -2614,14 +2605,22 @@ function (cotire_process_target_language _language _configurations _target _whol endif() cotire_generate_target_script( ${_language} "${_configurations}" ${_target} _targetScript _targetConfigScript ${_unitySourceFiles}) + # set up unity files for parallel compilation cotire_compute_unity_max_number_of_includes(${_target} _maxIncludes ${_unitySourceFiles}) cotire_make_unity_source_file_paths(${_language} ${_target} ${_maxIncludes} _unityFiles ${_unitySourceFiles}) - if (NOT _unityFiles) + list (LENGTH _unityFiles _numberOfUnityFiles) + if (_numberOfUnityFiles EQUAL 0) return() + elseif (_numberOfUnityFiles GREATER 1) + cotire_setup_unity_generation_commands( + ${_language} ${_target} "${_targetScript}" "${_targetConfigScript}" "${_unityFiles}" _cmds ${_unitySourceFiles}) endif() + # set up single unity file for prefix header generation + cotire_make_single_unity_source_file_path(${_language} ${_target} _unityFile) cotire_setup_unity_generation_commands( - ${_language} ${_target} "${_targetScript}" "${_targetConfigScript}" "${_unityFiles}" _cmds ${_unitySourceFiles}) + ${_language} ${_target} "${_targetScript}" "${_targetConfigScript}" "${_unityFile}" _cmds ${_unitySourceFiles}) cotire_make_prefix_file_path(${_language} ${_target} _prefixFile) + # set up prefix header if (_prefixFile) # check for user provided prefix header files get_property(_prefixHeaderFiles TARGET ${_target} PROPERTY COTIRE_${_language}_PREFIX_HEADER_INIT) @@ -2630,7 +2629,7 @@ function (cotire_process_target_language _language _configurations _target _whol ${_language} ${_target} "${_targetConfigScript}" "${_prefixFile}" _cmds ${_prefixHeaderFiles}) else() cotire_setup_prefix_generation_from_unity_command( - ${_language} ${_target} "${_targetConfigScript}" "${_prefixFile}" "${_unityFiles}" _cmds ${_unitySourceFiles}) + ${_language} ${_target} "${_targetConfigScript}" "${_prefixFile}" "${_unityFile}" _cmds ${_unitySourceFiles}) endif() # check if selected language has enough sources at all list (LENGTH _sourceFiles _numberOfSources) @@ -3032,7 +3031,7 @@ function (cotire_cleanup _binaryDir _cotireIntermediateDirName _targetName) # filter files in intermediate directory set (_filesToRemove "") foreach (_file ${_cotireFiles}) - get_filename_component(_dir "${_file}" PATH) + get_filename_component(_dir "${_file}" DIRECTORY) get_filename_component(_dirName "${_dir}" NAME) if ("${_dirName}" STREQUAL "${_cotireIntermediateDirName}") list (APPEND _filesToRemove "${_file}") @@ -3156,7 +3155,6 @@ if (CMAKE_SCRIPT_MODE_FILE) message (STATUS "COTIRE_BUILD_TYPE=${COTIRE_BUILD_TYPE} not cotired (${COTIRE_TARGET_CONFIGURATION_TYPES})") endif() set (_sources "") - set (_sourceLocations "") set (_sourcesDefinitions "") endif() set (_targetPreUndefs ${COTIRE_TARGET_PRE_UNDEFS}) @@ -3358,9 +3356,9 @@ else() endif() if (MSVC) # MSVC default PCH memory scaling factor of 100 percent (75 MB) is too small for template heavy C++ code - # use a bigger default factor of 140 percent (105 MB) + # use a bigger default factor of 170 percent (128 MB) if (NOT DEFINED COTIRE_PCH_MEMORY_SCALING_FACTOR) - set (COTIRE_PCH_MEMORY_SCALING_FACTOR "140") + set (COTIRE_PCH_MEMORY_SCALING_FACTOR "170") endif() endif() if (NOT COTIRE_UNITY_BUILD_TARGET_SUFFIX) diff --git a/libs/Common/AutoEstimator.h b/libs/Common/AutoEstimator.h index f2d09d083..ede488458 100644 --- a/libs/Common/AutoEstimator.h +++ b/libs/Common/AutoEstimator.h @@ -547,7 +547,7 @@ class ACKernelAdaptor inline double logalpha0() const { return logalpha0_; } inline double multError() const { return (bPointToLine_ ? 0.5 : 1.0); } -private: +protected: DMatrix32F x1_, x2_; // Normalized input data double logalpha0_; // Alpha0 is used to make the error adaptive to the image size bool bPointToLine_;// Store if error model is pointToLine or point to point @@ -597,7 +597,7 @@ class ACKernelAdaptorResection inline double logalpha0() const { return logalpha0_; } inline double multError() const { return 1.0; } // point to point error -private: +protected: DMatrix32F x2d_; DMatrix x3D_; double logalpha0_; // Alpha0 is used to make the error adaptive to the image size @@ -656,7 +656,7 @@ class ACKernelAdaptorEssential inline double logalpha0() const { return logalpha0_; } inline double multError() const { return 0.5; } // point to line error -private: +protected: Solver solver; DMatrix32F x1_, x2_; // image point and camera plane point. double logalpha0_; // Alpha0 is used to make the error adaptive to the image size diff --git a/libs/Common/AutoPtr.h b/libs/Common/AutoPtr.h index ab9a537b0..375cca446 100644 --- a/libs/Common/AutoPtr.h +++ b/libs/Common/AutoPtr.h @@ -134,11 +134,10 @@ class CAutoPtr m_pointer = _Ptr; } -private: +protected: TypePtr m_pointer; // the wrapped object pointer -#ifdef _USE_BOOST -protected: + #ifdef _USE_BOOST // implement BOOST serialization friend class boost::serialization::access; template @@ -154,7 +153,7 @@ class CAutoPtr operator=(newPointer); } BOOST_SERIALIZATION_SPLIT_MEMBER() -#endif + #endif }; @@ -248,11 +247,10 @@ class CAutoPtrArr m_pointer = _Ptr; } -private: +protected: TypePtr m_pointer; // the wrapped object pointer -#ifdef _USE_BOOST -protected: + #ifdef _USE_BOOST // implement BOOST serialization friend class boost::serialization::access; template @@ -268,7 +266,7 @@ class CAutoPtrArr operator=(newPointer); } BOOST_SERIALIZATION_SPLIT_MEMBER() -#endif + #endif }; /*----------------------------------------------------------------*/ diff --git a/libs/Common/CUDA.h b/libs/Common/CUDA.h index b5700a0ff..1ab9b5303 100644 --- a/libs/Common/CUDA.h +++ b/libs/Common/CUDA.h @@ -126,7 +126,7 @@ inline CUresult freeMemDevice(CUdeviceptr& dataDevice) { class MemDevice { -private: +protected: CUdeviceptr pData; size_t nSize; @@ -195,7 +195,7 @@ typedef CLISTDEFIDX(MemDevice,int) MemDeviceArr; class EventRT { -private: +protected: CUevent hEvent; protected: @@ -222,7 +222,7 @@ typedef CSharedPtr EventRTPtr; class StreamRT { -private: +protected: CUstream hStream; protected: @@ -251,7 +251,7 @@ typedef CSharedPtr StreamRTPtr; class ModuleRT { -private: +protected: CUmodule hModule; protected: @@ -393,7 +393,7 @@ class KernelRT } CUresult GetResult(const std::initializer_list& params) const; -private: +protected: CUresult _AddParam(const InputParam& param); CUresult _AddParam(const OutputParam& param); template @@ -453,7 +453,7 @@ class TArrayRT typedef TYPE Type; typedef TImage ImageType; -private: +protected: CUarray hArray; public: diff --git a/libs/Common/CriticalSection.h b/libs/Common/CriticalSection.h index 19ecd64cb..b7f03a601 100644 --- a/libs/Common/CriticalSection.h +++ b/libs/Common/CriticalSection.h @@ -211,8 +211,10 @@ class RLock { public: RLock(RWLock& aCs) : cs(aCs) { cs.EnterRead(); } ~RLock() { cs.LeaveRead(); } -protected: +private: + RLock(const RLock&); RLock& operator=(const RLock&); +protected: RWLock& cs; }; @@ -223,8 +225,10 @@ class RLockTry { bool IsLocked() const { return bLocked; } bool TryEnter() { return (bLocked = cs.TryEnterRead()); } bool TryLeave() { return !(bLocked = !cs.TryLeaveRead()); } +private: + RLockTry(const RLockTry&); + RLockTry& operator=(const RLockTry&); protected: - RLock& operator=(const RLock&); RWLock& cs; bool bLocked; }; @@ -233,8 +237,10 @@ class WLock { public: WLock(RWLock& aCs) : cs(aCs) { cs.EnterWrite(); } ~WLock() { cs.LeaveWrite(); } +private: + WLock(const WLock&); + WLock& operator=(const WLock&); protected: - RLock& operator=(const RLock&); RWLock& cs; }; @@ -244,8 +250,10 @@ class WLockTry { ~WLockTry() { if (bLocked) cs.LeaveWrite(); } bool IsLocked() const { return bLocked; } bool TryEnter() { return (bLocked = cs.TryEnterWrite()); } +private: + WLockTry(const WLockTry&); + WLockTry& operator=(const WLockTry&); protected: - RLock& operator=(const RLock&); RWLock& cs; bool bLocked; }; diff --git a/libs/Common/EventQueue.h b/libs/Common/EventQueue.h index 342e5c620..87f5c93f8 100644 --- a/libs/Common/EventQueue.h +++ b/libs/Common/EventQueue.h @@ -33,7 +33,7 @@ class Event virtual bool Run(void* /*pArgs*/) { return true; } -private: +protected: const uint32_t id; }; typedef cQueue EVENTQUEUE; @@ -64,7 +64,7 @@ class GENERAL_API EventQueue bool IsEmpty() const; //are there any events in the queue? uint_t GetSize() const; //number of events in the queue -private: +protected: Semaphore m_sem; mutable CriticalSection m_cs; EVENTQUEUE m_events; diff --git a/libs/Common/List.h b/libs/Common/List.h index 4a73be8a6..821fc86ed 100644 --- a/libs/Common/List.h +++ b/libs/Common/List.h @@ -339,7 +339,7 @@ class cList return (IDX)(pElem-vector); } - inline ARG_TYPE operator[](IDX index) const + inline const TYPE& operator[](IDX index) const { ASSERT(index < size); return vector[index]; @@ -369,7 +369,7 @@ class cList return vector+size; } - inline ARG_TYPE First() const + inline const TYPE& First() const { ASSERT(size > 0); return vector[0]; @@ -380,7 +380,7 @@ class cList return vector[0]; } - inline ARG_TYPE Last() const + inline const TYPE& Last() const { ASSERT(size > 0); return vector[size-1]; @@ -967,6 +967,7 @@ class cList inline ARG_TYPE RemoveTail() { ASSERT(size); + ASSERT(!useConstruct); return vector[--size]; } @@ -1253,9 +1254,7 @@ class cList }; template const typename cList::IDX -cList::NO_INDEX( - DECLARE_NO_INDEX(typename cList::IDX) -); +cList::NO_INDEX(DECLARE_NO_INDEX(IDX)); /*----------------------------------------------------------------*/ @@ -1410,6 +1409,155 @@ inline bool cListTest(unsigned iters) { #endif /*----------------------------------------------------------------*/ + + +/************************************************************************************** + * Fixed size list template + **************************************************************************************/ + +template +class cListFixed { +public: + typedef TYPE Type; + typedef const TYPE& ArgType; + typedef unsigned IDX; + enum {MAX_SIZE = N}; + + inline cListFixed() : size(0) {} + inline void CopyOf(const TYPE* pData, IDX nSize) { + memcpy(vector, pData, nSize); + size = nSize; + } + inline bool IsEmpty() const { + return (size == 0); + } + inline IDX GetSize() const { + return size; + } + inline const TYPE* Begin() const { + return vector; + } + inline TYPE* Begin() { + return vector; + } + inline const TYPE* End() const { + return vector+size; + } + inline TYPE* End() { + return vector+size; + } + inline const TYPE& First() const { + ASSERT(size > 0); + return vector[0]; + } + inline TYPE& First() { + ASSERT(size > 0); + return vector[0]; + } + inline const TYPE& Last() const { + ASSERT(size > 0); + return vector[size-1]; + } + inline TYPE& Last() { + ASSERT(size > 0); + return vector[size-1]; + } + inline const TYPE& operator[](IDX index) const { + ASSERT(index < size); + return vector[index]; + } + inline TYPE& operator[](IDX index) { + ASSERT(index < size); + return vector[index]; + } + inline TYPE& AddEmpty() { + ASSERT(size < N); + return vector[size++]; + } + inline void InsertAt(IDX index, ArgType elem) { + ASSERT(size < N); + memmove(vector+index+1, vector+index, sizeof(TYPE)*(size++ - index)); + vector[index] = elem; + } + inline void Insert(ArgType elem) { + ASSERT(size < N); + vector[size++] = elem; + } + inline void RemoveLast() { + ASSERT(size); + --size; + } + inline void RemoveAt(IDX index) { + ASSERT(index < size); + if (index+1 == size) + RemoveLast(); + else + memcpy(vector+index, vector+(--size), sizeof(TYPE)); + } + inline void Empty() { + size = 0; + } + inline void Sort() { + std::sort(Begin(), End()); + } + inline IDX Find(ArgType elem) const + { + IDX i = size; + while (i) + if (vector[--i] == elem) + return i; + return NO_INDEX; + } + inline IDX FindFirstEqlGreater(ArgType searchedKey) const { + if (size == 0) return 0; + IDX l1 = 0, l2 = size; + do { + IDX i = (l1 + l2) >> 1; + const TYPE& key = vector[i]; + if (key == searchedKey) { + while (i-- && vector[i] == searchedKey); + return i+1; + } + if (key < searchedKey) + l1 = i+1; + else + l2 = i; + } while (l1 < l2); + return l1; + } + inline void StoreTop(ArgType elem) { + const IDX idx(FindFirstEqlGreater(elem)); + if (idx < GetSize()) { + if (GetSize() >= N) + RemoveLast(); + InsertAt(idx, elem); + } else if (GetSize() < N) { + Insert(elem); + } + } + +protected: + TYPE vector[N]; + IDX size; + +public: + static const IDX NO_INDEX; + +#ifdef _USE_BOOST +protected: + // implement BOOST serialization + friend class boost::serialization::access; + template + void serialize(Archive& ar, const unsigned int /*version*/) { + ar & size; + ar & boost::serialization::make_array(vector, size); + } +#endif +}; +template +const typename cListFixed::IDX cListFixed::NO_INDEX(DECLARE_NO_INDEX(IDX)); +/*----------------------------------------------------------------*/ + } // namespace SEACAVE #endif // __SEACAVE_LIST_H__ diff --git a/libs/Common/Log.h b/libs/Common/Log.h index a0371a8ae..157cc6136 100644 --- a/libs/Common/Log.h +++ b/libs/Common/Log.h @@ -93,11 +93,11 @@ class GENERAL_API Log } #endif -private: +protected: // write a message of a certain type to the log void _Record(UINT, LPCTSTR, va_list); -private: +protected: struct LogType { TCHAR szName[LOGTYPE_SIZE+1]; inline operator LPCTSTR () const { return szName; } @@ -160,7 +160,7 @@ class GENERAL_API LogFile void Play(); void Record(const String&); -private: +protected: FilePtr m_ptrFile; // the log file }; #define GET_LOGFILE() LogFile::GetInstance() @@ -185,7 +185,7 @@ class GENERAL_API LogConsole void Play(); void Record(const String&); -private: +protected: #ifdef _USE_COSOLEFILEHANDLES typedef FILE* StreamHandle; #else diff --git a/libs/Common/Octree.h b/libs/Common/Octree.h index 28b0a36fe..11daf98a3 100644 --- a/libs/Common/Octree.h +++ b/libs/Common/Octree.h @@ -38,7 +38,7 @@ class TItemArr inline const TYPE* GetData() const { return m_data; } inline IDX GetSize() const { return m_size; } -private: +protected: const TYPE* m_data; IDX m_size; }; // class TItemArr @@ -183,7 +183,7 @@ class TOctree inline const IDXARR_TYPE& GetIndexArr() const { return m_indices; } inline const ITEM_TYPE* GetItems() const { return m_items; } -private: +protected: static inline POINT_TYPE ComputeChildCenter(const POINT_TYPE&, TYPE, unsigned); void _Insert(CELL_TYPE&, TYPE, IDXARR_TYPE []); @@ -204,7 +204,7 @@ class TOctree template void _TraverseCells(CELL_TYPE&, TYPE, const TFrustum&, PARSER&); -private: +protected: const ITEM_TYPE* m_items; // original input items (the only condition is that every item to resolve to a position) IDXARR_TYPE m_indices; // indices to input items re-arranged spatially (as dictated by the octree) CELL_TYPE m_root; // first cell of the tree (always of Node type) @@ -236,7 +236,7 @@ class TOctree void GetDebugInfo(DEBUGINFO* =NULL, bool bPrintStats=false) const; static void LogDebugInfo(const DEBUGINFO&); -private: +protected: void _GetDebugInfo(const CELL_TYPE&, unsigned, DEBUGINFO&) const; #endif }; // class TOctree diff --git a/libs/Common/SharedPtr.h b/libs/Common/SharedPtr.h index 298268294..3488802d7 100644 --- a/libs/Common/SharedPtr.h +++ b/libs/Common/SharedPtr.h @@ -74,7 +74,7 @@ struct SharedRef { template class CSharedPtr { -private: +protected: typedef SharedRef TYPE_REF; typedef TYPE* TYPE_PTR; @@ -165,7 +165,7 @@ class CSharedPtr m_pNoRef = NULL; } -private: +protected: inline void IncRef() { if (m_pointer == NULL) diff --git a/libs/Common/Thread.h b/libs/Common/Thread.h index d354f8df0..4825a93e1 100644 --- a/libs/Common/Thread.h +++ b/libs/Common/Thread.h @@ -194,7 +194,7 @@ class Thread protected: virtual void run() {} -private: +protected: #ifdef _MSC_VER enum PriorityOS { @@ -246,7 +246,7 @@ class Thread return NULL; } -private: +protected: thread_t threadHandle; #ifdef _MSC_VER DWORD threadId; @@ -295,7 +295,7 @@ class Process static inline void setCurrentProcessPriority(Priority p) { setProcessPriority(getCurrentProcessID(), p); } static inline Priority getCurrentProcessPriority() { return getProcessPriority(getCurrentProcessID()); } -private: +protected: #ifdef _MSC_VER diff --git a/libs/Common/Timer.h b/libs/Common/Timer.h index c7c08e307..f9160995e 100644 --- a/libs/Common/Timer.h +++ b/libs/Common/Timer.h @@ -101,7 +101,7 @@ class GENERAL_API Timer return 0.001f * ms_fTimeFactor * t; } -private: +protected: #ifdef TIMER_OLDSUPPORT static const bool ms_bPerfFlag; // flag for timer to use #endif @@ -117,7 +117,7 @@ class AutoTimer public: AutoTimer(Type& duration) : m_duration(duration) { m_duration = Timer::GetTime(); } ~AutoTimer() { m_duration = Timer::GetTime() - m_duration; } -private: +protected: Type& m_duration; }; @@ -128,7 +128,7 @@ class AutoAddTimer public: AutoAddTimer(Type& duration) : m_duration(duration) { m_lastTime = Timer::GetTime(); } ~AutoAddTimer() { m_duration += Timer::GetTime() - m_lastTime; } -private: +protected: Type& m_duration; Type m_lastTime; }; diff --git a/libs/Common/Types.h b/libs/Common/Types.h index ce631af37..ea84c8159 100644 --- a/libs/Common/Types.h +++ b/libs/Common/Types.h @@ -108,7 +108,6 @@ namespace boost { void throw_exception(std::exception const&); } #include #endif -#define _USE_EIGEN #ifdef _USE_EIGEN #include #include @@ -254,7 +253,7 @@ typedef uint32_t uint_t; // type used for the size of the files typedef int64_t size_f_t; -#define DECLARE_NO_INDEX(...) (std::numeric_limits<__VA_ARGS__>::max()) +#define DECLARE_NO_INDEX(...) std::numeric_limits<__VA_ARGS__>::max() #define NO_ID DECLARE_NO_INDEX(uint32_t) #ifndef MAKEWORD @@ -1846,7 +1845,7 @@ struct TPixel { template inline TPixel(const TPixel& p) : r(TYPE(p.r)), g(TYPE(p.g)), b(TYPE(p.b)) {} inline TPixel(TYPE _r, TYPE _g, TYPE _b) : r(_r), g(_g), b(_b) {} inline TPixel(const Pnt& col) : c0(col.x), c1(col.y), c2(col.z) {} - inline TPixel(uint32_t col) : r((col>>16)&0xFF), g((col>>8)&0xFF), b(col&0xFF) {} + explicit inline TPixel(uint32_t col) : r((col>>16)&0xFF), g((col>>8)&0xFF), b(col&0xFF) {} // set/get from default type inline void set(TYPE _r, TYPE _g, TYPE _b) { r = _r; g = _g; b = _b; } inline void set(const TYPE* clr) { c[0] = clr[0]; c[1] = clr[1]; c[2] = clr[2]; } @@ -1883,7 +1882,7 @@ struct TPixel { inline TPixel operator-(const TPixel& v) const { return TPixel(r-v.r, g-v.g, b-v.b); } template inline TPixel operator-(T v) const { return TPixel((TYPE)(r-v), (TYPE)(g-v), (TYPE)(b-v)); } template inline TPixel& operator-=(T v) { return (*this = operator-(v)); } - inline operator uint32_t () const { return RGBA((uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)0); } + inline uint32_t toDWORD() const { return RGBA((uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)0); } #ifdef _USE_BOOST // serialize template @@ -1951,7 +1950,7 @@ struct TColor { #if _COLORMODE == _COLORMODE_RGB inline TColor(const Pnt& col, TYPE _a=ColorType::ONE) : r(col.x), g(col.y), b(col.z), a(_a) {} #endif - inline TColor(uint32_t col) : r((col>>16)&0xFF), g((col>>8)&0xFF), b(col&0xFF), a((col>>24)&0xFF) {} + explicit inline TColor(uint32_t col) : r((col>>16)&0xFF), g((col>>8)&0xFF), b(col&0xFF), a((col>>24)&0xFF) {} // set/get from default type inline void set(TYPE _r, TYPE _g, TYPE _b, TYPE _a=ColorType::ONE) { r = _r; g = _g; b = _b; a = _a; } inline void set(const TYPE* clr) { c[0] = clr[0]; c[1] = clr[1]; c[2] = clr[2]; c[3] = clr[3]; } @@ -1989,7 +1988,7 @@ struct TColor { inline TColor operator-(const TColor& v) const { return TColor(r-v.r, g-v.g, b-v.b, a-v.a); } template inline TColor operator-(T v) const { return TColor((TYPE)(r-v), (TYPE)(g-v), (TYPE)(b-v), (TYPE)(a-v)); } template inline TColor& operator-=(T v) { return (*this = operator-(v)); } - inline operator uint32_t () const { return RGBA((uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)a); } + inline uint32_t toDWORD() const { return RGBA((uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)a); } #ifdef _USE_BOOST // serialize template @@ -2004,7 +2003,7 @@ template <> inline void TColor::set(float _r, float _g, float _b, float template <> inline void TColor::get(float& _r, float& _g, float& _b, float& _a) const { _r = float(r)/255; _g = float(g)/255; _b = float(b)/255; _a = float(a)/255; } template <> inline bool TColor::operator==(const TColor& col) const { return (*((const uint32_t*)c) == *((const uint32_t*)col.c)); } template <> inline bool TColor::operator!=(const TColor& col) const { return (*((const uint32_t*)c) != *((const uint32_t*)col.c)); } -template <> inline TColor::operator uint32_t () const { return *((const uint32_t*)c); } +template <> inline uint32_t TColor::toDWORD() const { return *((const uint32_t*)c); } /*----------------------------------------------------------------*/ typedef TColor Color8U; typedef TColor Color32F; @@ -2469,13 +2468,13 @@ class SO3 typedef Matrix Vec3; /// Default constructor. Initializes the matrix to the identity (no rotation) - inline SO3() : my_matrix(Mat3::Identity()) {} + inline SO3() : mat(Mat3::Identity()) {} /// Construct from a rotation matrix. - inline SO3(const Mat3& rhs) : my_matrix(rhs) {} + inline SO3(const Mat3& rhs) : mat(rhs) {} /// Construct from the axis of rotation (and angle given by the magnitude). - inline SO3(const Vec3& v) : my_matrix(exp(v)) {} + inline SO3(const Vec3& v) : mat(exp(v)) {} /// creates an SO3 as a rotation that takes Vector a into the direction of Vector b /// with the rotation axis along a ^ b. If |a ^ b| == 0, it creates the identity rotation. @@ -2491,7 +2490,7 @@ class SO3 // check that the vectors are in the same direction if cross product is 0; if not, // this means that the rotation is 180 degrees, which leads to an ambiguity in the rotation axis ASSERT(a.dot(b) >= Precision(0)); - my_matrix = Mat3::Identity(); + mat = Mat3::Identity(); return; } n *= Precision(1)/sqrt(nrmSq); @@ -2499,33 +2498,33 @@ class SO3 R1.col(0) = a.normalized(); R1.col(1) = n; R1.col(2) = R1.col(0).cross(n); - my_matrix.col(0) = b.normalized(); - my_matrix.col(1) = n; - my_matrix.col(2) = my_matrix.col(0).cross(n); - my_matrix = my_matrix * R1.transpose(); + mat.col(0) = b.normalized(); + mat.col(1) = n; + mat.col(2) = mat.col(0).cross(n); + mat = mat * R1.transpose(); } /// Assignment operator from a general matrix. This also calls coerce() /// to make sure that the matrix is a valid rotation matrix. inline SO3& operator=(const Mat3& rhs) { - my_matrix = rhs; + mat = rhs; coerce(); return *this; } /// Modifies the matrix to make sure it is a valid rotation matrix. void coerce() { - my_matrix.row(0).normalize(); - const Precision d01(my_matrix.row(0).dot(my_matrix.row(1))); - my_matrix.row(1) -= my_matrix.row(0) * d01; - my_matrix.row(1).normalize(); - const Precision d02(my_matrix.row(0).dot(my_matrix.row(2))); - my_matrix.row(2) -= my_matrix.row(0) * d02; - const Precision d12(my_matrix.row(1).dot(my_matrix.row(2))); - my_matrix.row(2) -= my_matrix.row(1) * d12; - my_matrix.row(2).normalize(); + mat.row(0).normalize(); + const Precision d01(mat.row(0).dot(mat.row(1))); + mat.row(1) -= mat.row(0) * d01; + mat.row(1).normalize(); + const Precision d02(mat.row(0).dot(mat.row(2))); + mat.row(2) -= mat.row(0) * d02; + const Precision d12(mat.row(1).dot(mat.row(2))); + mat.row(2) -= mat.row(1) * d12; + mat.row(2).normalize(); // check for positive determinant <=> right handed coordinate system of row vectors - ASSERT(my_matrix.row(0).cross(my_matrix.row(1)).dot(my_matrix.row(2)) > 0); + ASSERT(mat.row(0).cross(mat.row(1)).dot(mat.row(2)) > 0); } /// Exponentiate a vector in the Lie algebra to generate a new SO3. @@ -2547,7 +2546,7 @@ class SO3 inline SO3 operator *(const SO3& rhs) const { return SO3(*this, rhs); } /// Returns the SO3 as a Matrix<3> - inline const Mat3& get_matrix() const { return my_matrix; } + inline const Mat3& get_matrix() const { return mat; } /// Returns the i-th generator. The generators of a Lie group are the basis /// for the space of the Lie algebra. For %SO3, the generators are three @@ -2570,10 +2569,29 @@ class SO3 } template - inline SO3(const SO3& a, const SO3& b) : my_matrix(a.get_matrix()*b.get_matrix()) {} + inline SO3(const SO3& a, const SO3& b) : mat(a.get_matrix()*b.get_matrix()) {} -private: - Mat3 my_matrix; +protected: + Mat3 mat; + + #ifdef _USE_BOOST + // implement BOOST serialization + friend class boost::serialization::access; + template + void save(Archive& ar, const unsigned int /*version*/) const + { + Vec3 comp(ln()); + ar & comp; + } + template + void load(Archive& ar, const unsigned int /*version*/) + { + Vec3 comp; + ar & comp; + mat = exp(comp); + } + BOOST_SERIALIZATION_SPLIT_MEMBER() + #endif }; /*----------------------------------------------------------------*/ @@ -2591,26 +2609,26 @@ class SO2 typedef Matrix Mat2; /// Default constructor. Initializes the matrix to the identity (no rotation) - inline SO2() : my_matrix(Mat2::Identity()) {} + inline SO2() : mat(Mat2::Identity()) {} /// Construct from a rotation matrix. - inline SO2(const Mat2& rhs) : my_matrix(rhs) {} + inline SO2(const Mat2& rhs) : mat(rhs) {} /// Construct from an angle. - inline SO2(const Precision l) : my_matrix(exp(l)) {} + inline SO2(const Precision l) : mat(exp(l)) {} /// Assigment operator from a general matrix. This also calls coerce() /// to make sure that the matrix is a valid rotation matrix. inline SO2& operator=(const Mat2& rhs) { - my_matrix = rhs; + mat = rhs; coerce(); return *this; } /// Modifies the matrix to make sure it is a valid rotation matrix. inline void coerce() { - my_matrix.row(0).normalize(); - my_matrix.row(1) = (my_matrix.row(1) - my_matrix.row(0) * (my_matrix.row(0).dot(my_matrix.row(1)))).normalized(); + mat.row(0).normalize(); + mat.row(1) = (mat.row(1) - mat.row(0) * (mat.row(0).dot(mat.row(1)))).normalized(); } /// Exponentiate an angle in the Lie algebra to generate a new SO2. @@ -2621,7 +2639,7 @@ class SO2 /// Self right-multiply by another rotation matrix inline SO2& operator *=(const SO2& rhs) { - my_matrix = my_matrix*rhs.get_matrix(); + mat = mat*rhs.get_matrix(); return *this; } @@ -2629,7 +2647,7 @@ class SO2 inline SO2 operator *(const SO2& rhs) const { return SO2(*this, rhs); } /// Returns the SO2 as a Matrix<2> - inline const Mat2& get_matrix() const { return my_matrix; } + inline const Mat2& get_matrix() const { return mat; } /// returns generator matrix inline static Mat2 generator() { @@ -2639,8 +2657,27 @@ class SO2 return result; } -private: - Mat2 my_matrix; +protected: + Mat2 mat; + + #ifdef _USE_BOOST + // implement BOOST serialization + friend class boost::serialization::access; + template + void save(Archive& ar, const unsigned int /*version*/) const + { + Precision comp(ln()); + ar & comp; + } + template + void load(Archive& ar, const unsigned int /*version*/) + { + Precision comp; + ar & comp; + mat = exp(comp); + } + BOOST_SERIALIZATION_SPLIT_MEMBER() + #endif }; /*----------------------------------------------------------------*/ diff --git a/libs/Common/Types.inl b/libs/Common/Types.inl index 055d9a71d..8e5a6386c 100644 --- a/libs/Common/Types.inl +++ b/libs/Common/Types.inl @@ -2992,7 +2992,7 @@ inline void eigen_SO3_ln(const typename Eigen::SO3::Mat3& R, typename template inline typename Eigen::SO3::Vec3 Eigen::SO3::ln() const { Vec3 result; - eigen_SO3_ln(my_matrix, result); + eigen_SO3_ln(mat, result); return result; } @@ -3006,7 +3006,7 @@ inline std::ostream& operator<<(std::ostream& os, const Eigen::SO3& r /// @relates SO3 template inline std::istream& operator>>(std::istream& is, Eigen::SO3& rhs) { - is >> rhs.my_matrix; + is >> rhs.mat; rhs.coerce(); return is; } @@ -3060,7 +3060,7 @@ inline void eigen_SO2_ln(const typename Eigen::SO2::Mat2& R, Precisio template inline Precision Eigen::SO2::ln() const { Precision d; - eigen_SO2_ln(my_matrix, d); + eigen_SO2_ln(mat, d); return d; } @@ -3074,7 +3074,7 @@ inline std::ostream& operator<<(std::ostream& os, const Eigen::SO2 & /// @relates SO2 template inline std::istream& operator>>(std::istream& is, Eigen::SO2& rhs) { - is >> rhs.my_matrix; + is >> rhs.mat; rhs.coerce(); return is; } diff --git a/libs/Common/Util.cpp b/libs/Common/Util.cpp index 4df6a7691..abf0a7e04 100644 --- a/libs/Common/Util.cpp +++ b/libs/Common/Util.cpp @@ -414,24 +414,6 @@ String Util::GetOSInfo() } /*----------------------------------------------------------------*/ -uint64_t Util::GetHardwareFingerprint() -{ - #ifdef _MSC_VER - QueryWMI query; - if (!query.IsOpen()) - return 0; - const String hfp("CPU: " + query.cpuId() + "\nBIOS: " + query.biosId() + "\nBASE: " + query.baseId() - //+ "\nDISK: "+ query.diskId() + "\nVIDEO: " + query.videoId() + "\nMAC: "+ query.macId() - ); - return CRC64(hfp.c_str(), hfp.length()); - #else // _MSC_VER - //TODO: implement - exit(-1); - return 0; - #endif // _MSC_VER -} -/*----------------------------------------------------------------*/ - /** * Set global variable for availability of SSE instructions. @@ -731,256 +713,3 @@ LPSTR* Util::CommandLineToArgvA(LPCSTR CmdLine, size_t& _argc) return argv; } /*----------------------------------------------------------------*/ - - - -// C L A S S /////////////////////////////////////////////////////// - -#ifdef _MSC_VER - -#include -#include -#include - -# pragma comment(lib, "wbemuuid.lib") - -QueryWMI::QueryWMI() - : - vpLoc(NULL), vpSvc(NULL) -{ - HRESULT hres; - typedef IWbemLocator* PIWbemLocator; - PIWbemLocator& pLoc(reinterpret_cast(vpLoc)); - typedef IWbemServices* PIWbemServices; - PIWbemServices& pSvc(reinterpret_cast(vpSvc)); - - // Step 1: -------------------------------------------------- - // Initialize COM. ------------------------------------------ - - hres = CoInitializeEx(0, COINIT_MULTITHREADED); - if (FAILED(hres)) { - std::cout << "Failed to initialize COM library. Error code = 0x" << std::hex << hres << std::endl; - return; // Program has failed. - } - - // Step 2: -------------------------------------------------- - // Set general COM security levels -------------------------- - - hres = CoInitializeSecurity( - NULL, - -1, // COM authentication - NULL, // Authentication services - NULL, // Reserved - RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication - RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation - NULL, // Authentication info - EOAC_NONE, // Additional capabilities - NULL // Reserved - ); - - if (FAILED(hres)) { - std::cout << "Failed to initialize security. Error code = 0x" << std::hex << hres << std::endl; - Release(); - return; // Program has failed. - } - - // Step 3: --------------------------------------------------- - // Obtain the initial locator to WMI ------------------------- - - hres = CoCreateInstance( - CLSID_WbemLocator, - 0, - CLSCTX_INPROC_SERVER, - IID_IWbemLocator, (LPVOID *) &pLoc); - - if (FAILED(hres)) { - std::cout << "Failed to create IWbemLocator object." << " Err code = 0x" << std::hex << hres << std::endl; - Release(); - return; // Program has failed. - } - - // Step 4: ----------------------------------------------------- - // Connect to WMI through the IWbemLocator::ConnectServer method - - // Connect to the root\cimv2 namespace with - // the current user and obtain pointer pSvc - // to make IWbemServices calls. - hres = pLoc->ConnectServer( - _bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace - NULL, // User name. NULL = current user - NULL, // User password. NULL = current - 0, // Locale. NULL indicates current - NULL, // Security flags. - 0, // Authority (for example, Kerberos) - 0, // Context object - &pSvc // pointer to IWbemServices proxy - ); - - if (FAILED(hres)) { - std::cout << "Could not connect. Error code = 0x" << std::hex << hres << std::endl; - Release(); - return; // Program has failed. - } - - //std::cout << "Connected to ROOT\\CIMV2 WMI namespace" << std::endl; - - - // Step 5: -------------------------------------------------- - // Set security levels on the proxy ------------------------- - - hres = CoSetProxyBlanket( - pSvc, // Indicates the proxy to set - RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx - RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx - NULL, // Server principal name - RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx - RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx - NULL, // client identity - EOAC_NONE // proxy capabilities - ); - - if (FAILED(hres)) { - std::cout << "Could not set proxy blanket. Error code = 0x" << std::hex << hres << std::endl; - Release(); - return; // Program has failed. - } -} - -void QueryWMI::Release() -{ - if (vpSvc) { - ((IWbemServices*)vpSvc)->Release(); - vpSvc = NULL; - } - if (vpLoc) { - ((IWbemLocator*)vpLoc)->Release(); - vpLoc = NULL; - } - CoUninitialize(); -} - -String QueryWMI::Query(String wmiClass, String wmiProperty, String wmiCondition) -{ - HRESULT hres; - String query; - - typedef IWbemServices* PIWbemServices; - PIWbemServices& pSvc(reinterpret_cast(vpSvc)); - - // Step 6: -------------------------------------------------- - // Use the IWbemServices pointer to make requests of WMI ---- - - // For example, get the name of the operating system - IEnumWbemClassObject* pEnumerator(NULL); - hres = pSvc->ExecQuery( - bstr_t("WQL"), - bstr_t("SELECT * FROM ") + bstr_t(wmiClass.c_str()), - WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, - NULL, - &pEnumerator); - - if (FAILED(hres)) { - std::cout << "Query for operating system name failed." << " Error code = 0x" << std::hex << hres << std::endl; - Release(); - return query; // Program has failed. - } - - // Step 7: ------------------------------------------------- - // Get the data from the query in step 6 ------------------- - - VARIANT vtProp; - while (pEnumerator) { - ULONG uReturn = 0; - IWbemClassObject* pclsObj; - hres = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); - if (FAILED(hres) || 0 == uReturn) - break; - - if (wmiCondition.empty()) { - // Get the value of the Name property - hres = pclsObj->Get(bstr_t(wmiProperty.c_str()), 0, &vtProp, NULL, NULL); - if (SUCCEEDED(hres) && vtProp.vt == CIM_STRING) { - query += Util::toString(vtProp.bstrVal); - VariantClear(&vtProp); - } - } else { - // Check condition value to be True - hres = pclsObj->Get(bstr_t(wmiCondition.c_str()), 0, &vtProp, NULL, NULL); - if (SUCCEEDED(hres) && vtProp.vt == CIM_BOOLEAN && vtProp.boolVal) { - // Get the value of the Name property - hres = pclsObj->Get(bstr_t(wmiProperty.c_str()), 0, &vtProp, NULL, NULL); - if (SUCCEEDED(hres) && vtProp.vt == CIM_STRING) { - query += Util::toString(vtProp.bstrVal); - VariantClear(&vtProp); - } - } - } - - pclsObj->Release(); - } - - // Cleanup - // ======== - - pEnumerator->Release(); - - return query; -} - -String QueryWMI::cpuId() -{ - //Uses first CPU identifier available in order of preference - //Don't get all identifiers, as very time consuming - String retVal(Query("Win32_Processor", "UniqueId")); - if (retVal.empty()) { //If no UniqueID, use ProcessorID - retVal = Query("Win32_Processor", "ProcessorId"); - if (retVal.empty()) { //If no ProcessorId, use Name - retVal = Query("Win32_Processor", "Name"); - if (retVal.empty()) //If no Name, use Manufacturer - retVal = Query("Win32_Processor", "Manufacturer"); - //Add clock speed for extra security - retVal += Query("Win32_Processor", "MaxClockSpeed"); - } - } - return retVal; -} -//BIOS Identifier -String QueryWMI::biosId() -{ - return Query("Win32_BIOS", "Manufacturer") - + Query("Win32_BIOS", "SMBIOSBIOSVersion") - + Query("Win32_BIOS", "IdentificationCode") - + Query("Win32_BIOS", "SerialNumber") - + Query("Win32_BIOS", "ReleaseDate") - + Query("Win32_BIOS", "Version"); -} -//Main physical hard drive ID -String QueryWMI::diskId() -{ - return Query("Win32_DiskDrive", "Model") - + Query("Win32_DiskDrive", "Manufacturer") - + Query("Win32_DiskDrive", "Signature") - + Query("Win32_DiskDrive", "TotalHeads"); -} -//Motherboard ID -String QueryWMI::baseId() -{ - return Query("Win32_BaseBoard", "Model") - + Query("Win32_BaseBoard", "Manufacturer") - + Query("Win32_BaseBoard", "Name") - + Query("Win32_BaseBoard", "SerialNumber"); -} -//Primary video controller ID -String QueryWMI::videoId() -{ - return Query("Win32_VideoController", "DriverVersion") - + Query("Win32_VideoController", "Name"); -} -//First enabled network card ID -String QueryWMI::macId() -{ - return Query("Win32_NetworkAdapterConfiguration", "MACAddress", "IPEnabled"); -} -/*----------------------------------------------------------------*/ - -#endif // _MSC_VER diff --git a/libs/Common/Util.h b/libs/Common/Util.h index 914b69e1e..2a4b000e4 100644 --- a/libs/Common/Util.h +++ b/libs/Common/Util.h @@ -68,17 +68,16 @@ class TFlags inline void operator=(TFlags rhs) { flags = rhs.flags; } inline operator Type() const { return flags; } inline operator Type&() { return flags; } -private: - Type flags; -#ifdef _USE_BOOST protected: + Type flags; + #ifdef _USE_BOOST // implement BOOST serialization friend class boost::serialization::access; template void serialize(Archive& ar, const unsigned int /*version*/) { ar & flags; } -#endif + #endif }; typedef class GENERAL_API TFlags Flags; /*----------------------------------------------------------------*/ @@ -184,7 +183,7 @@ class THistogram return os.str(); } -private: +protected: const Type Start, End, BinInterval; // min/max/step of values std::vector Freq; // histogram size_t Overflow, Underflow; // count under/over flow @@ -638,7 +637,6 @@ class GENERAL_API Util static String GetCPUInfo(); static String GetRAMInfo(); static String GetOSInfo(); - static uint64_t GetHardwareFingerprint(); enum CPUFNC {NA=0, SSE, AVX}; static const Flags ms_CPUFNC; @@ -699,35 +697,6 @@ class GENERAL_API Util }; /*----------------------------------------------------------------*/ - -#ifdef _MSC_VER - -class QueryWMI -{ -public: - QueryWMI(); - ~QueryWMI() { Release(); } - - void Release(); - inline bool IsOpen() const { return vpSvc != NULL; } - - String Query(String wmiClass, String wmiProperty, String wmiCondition=String()); - - String cpuId(); - String biosId(); - String diskId(); - String baseId(); - String videoId(); - String macId(); - -private: - void* vpLoc; - void* vpSvc; -}; -/*----------------------------------------------------------------*/ - -#endif // _MSC_VER - } // namespace SEACAVE #endif // __SEACAVE_UTIL_H__ diff --git a/libs/IO/OBJ.h b/libs/IO/OBJ.h index 852c5bf7d..968c2289e 100644 --- a/libs/IO/OBJ.h +++ b/libs/IO/OBJ.h @@ -82,7 +82,7 @@ class ObjModel { typedef std::vector Normals; typedef std::vector Groups; -private: +protected: Vertices vertices; TexCoords texcoords; Normals normals; diff --git a/libs/IO/PLY.h b/libs/IO/PLY.h index 66ff48be6..3460f5456 100644 --- a/libs/IO/PLY.h +++ b/libs/IO/PLY.h @@ -136,7 +136,7 @@ class PLY std::string name; }; -private: +protected: struct ValueType { union { int8_t i8; @@ -207,7 +207,7 @@ class PLY static inline bool equal_strings(const char* s1, const char* s2) { return _tcscmp(s1, s2) == 0; } -private: +protected: /* find an element in a ply's list */ PlyElement* find_element(const char *) const; @@ -297,7 +297,7 @@ class PLY PlyRuleList *rule_list; /* rule list from user */ std::vector vals; /* rule list from user */ -private: +protected: static const char *type_names[9]; // names of scalar types static const char *old_type_names[9]; // old names of types for backward compatibility static const int ply_type_size[9]; diff --git a/libs/MVS/DepthMap.cpp b/libs/MVS/DepthMap.cpp index 1863241c6..8faf25794 100644 --- a/libs/MVS/DepthMap.cpp +++ b/libs/MVS/DepthMap.cpp @@ -69,6 +69,7 @@ DEFVAR_OPTDENSE_uint32(nMinViewsFilter, "Min Views Filter", "minimum number of i MDEFVAR_OPTDENSE_uint32(nMinViewsFilterAdjust, "Min Views Filter Adjust", "minimum number of images that agrees with an estimate in order to consider it inlier (0 - disabled)", "1") MDEFVAR_OPTDENSE_uint32(nMinViewsTrustPoint, "Min Views Trust Point", "min-number of views so that the point is considered for approximating the depth-maps (<2 - random initialization)", "2") MDEFVAR_OPTDENSE_uint32(nNumViews, "Num Views", "Number of views used for depth-map estimation (0 - all views available)", "1", "0") +MDEFVAR_OPTDENSE_bool(bFilterAdjust, "Filter Adjust", "adjust depth estimates during filtering", "1") MDEFVAR_OPTDENSE_bool(bAddCorners, "Add Corners", "add support points at image corners with nearest neighbor disparities", "1") MDEFVAR_OPTDENSE_float(fViewMinScore, "View Min Score", "Min score to consider a neighbor images (0 - disabled)", "2.0") MDEFVAR_OPTDENSE_float(fViewMinScoreRatio, "View Min Score Ratio", "Min score ratio to consider a neighbor images", "0.3") @@ -536,7 +537,7 @@ class PlaneSolverAdaptor inline double logalpha0() const { return logalpha0_; } inline double multError() const { return 0.5; } -private: +protected: const Point3Arr& points_; // Normalized input data double logalpha0_; // Alpha0 is used to make the error adaptive to the image size Model model2evaluate; // current model to be evaluated diff --git a/libs/MVS/DepthMap.h b/libs/MVS/DepthMap.h index eb874f420..1fb41a3d6 100644 --- a/libs/MVS/DepthMap.h +++ b/libs/MVS/DepthMap.h @@ -66,6 +66,7 @@ extern unsigned nMinViewsFilter; extern unsigned nMinViewsFilterAdjust; extern unsigned nMinViewsTrustPoint; extern unsigned nNumViews; +extern bool bFilterAdjust; extern bool bAddCorners; extern float fViewMinScore; extern float fViewMinScoreRatio; @@ -75,7 +76,6 @@ extern float fMaxAngle; extern float fDescriptorMinMagnitudeThreshold; extern float fDepthDiffThreshold; extern float fPairwiseMul; -extern float fPointFilter; extern float fOptimizerEps; extern int nOptimizerMaxIters; extern unsigned nSpeckleSize; diff --git a/libs/MVS/Mesh.h b/libs/MVS/Mesh.h index 04a733096..2abde1160 100644 --- a/libs/MVS/Mesh.h +++ b/libs/MVS/Mesh.h @@ -152,7 +152,7 @@ class Mesh static inline VIndex GetVertex(const Face& f, VIndex v) { const uint32_t idx(FindVertex(f, v)); ASSERT(idx != NO_ID); return f[idx]; } static inline VIndex& GetVertex(Face& f, VIndex v) { const uint32_t idx(FindVertex(f, v)); ASSERT(idx != NO_ID); return f[idx]; } -private: +protected: bool LoadPLY(const String& fileName); bool LoadOBJ(const String& fileName); @@ -163,9 +163,9 @@ class Mesh static bool InitKernels(int device=-1); #endif -public: #ifdef _USE_BOOST // implement BOOST serialization + friend class boost::serialization::access; template void serialize(Archive& ar, const unsigned int /*version*/) { ar & vertices; diff --git a/libs/MVS/RectsBinPack.h b/libs/MVS/RectsBinPack.h index 39664f45b..9b466406f 100644 --- a/libs/MVS/RectsBinPack.h +++ b/libs/MVS/RectsBinPack.h @@ -102,7 +102,7 @@ class MaxRectsBinPack && a.y+a.height <= b.y+b.height; } -private: +protected: int binWidth; int binHeight; @@ -261,7 +261,7 @@ class GuillotineBinPack /// can be represented with a single rectangle. Takes up Theta(|freeRectangles|^2) time. void MergeFreeList(); -private: +protected: int binWidth; int binHeight; @@ -345,7 +345,7 @@ class SkylineBinPack /// Computes the ratio of used surface area to the total bin area. float Occupancy() const; -private: +protected: int binWidth; int binHeight; diff --git a/libs/MVS/SceneDensify.cpp b/libs/MVS/SceneDensify.cpp index 03aaffda8..f7a1c73a7 100644 --- a/libs/MVS/SceneDensify.cpp +++ b/libs/MVS/SceneDensify.cpp @@ -137,8 +137,8 @@ class DepthMapsData bool RemoveSmallSegments(DepthData& depthData); bool GapInterpolation(DepthData& depthData); - bool FilterDepthMapAdjust(DepthData& depthData, const IndexArr& idxNeighbors); - void FuseFilterDepthMaps(PointCloud& pointcloud, bool bEstimateNormal); + bool FilterDepthMap(DepthData& depthData, const IndexArr& idxNeighbors, bool bAdjust=true); + void FuseDepthMaps(PointCloud& pointcloud, bool bEstimateNormal); protected: static void* STCALL ScoreDepthMapTmp(void*); @@ -1033,9 +1033,8 @@ bool DepthMapsData::GapInterpolation(DepthData& depthData) /*----------------------------------------------------------------*/ -// filter depth-map, one pixel at a time, using confidence based fusion -// (inspired by: "Real-Time Visibility-Based Fusion of Depth Maps", Merrell, 2007) -bool DepthMapsData::FilterDepthMapAdjust(DepthData& depthDataRef, const IndexArr& idxNeighbors) +// filter depth-map, one pixel at a time, using confidence based fusion or neighbor pixels +bool DepthMapsData::FilterDepthMap(DepthData& depthDataRef, const IndexArr& idxNeighbors, bool bAdjust) { TD_TIMER_STARTD(); @@ -1061,8 +1060,10 @@ bool DepthMapsData::FilterDepthMapAdjust(DepthData& depthDataRef, const IndexArr depthMap.create(sizeRef); depthMap.memset(0); ConfidenceMap& confMap = confMaps[n]; - confMap.create(sizeRef); - confMap.memset(0); + if (bAdjust) { + confMap.create(sizeRef); + confMap.memset(0); + } const uint32_t idxView = depthDataRef.neighbors[idxNeighbors[n]].idx.ID; const DepthData& depthData = arrDepthData[idxView]; const Camera& camera = depthData.images.First().camera; @@ -1087,7 +1088,8 @@ bool DepthMapsData::FilterDepthMapAdjust(DepthData& depthDataRef, const IndexArr if (depthRef != 0 && depthRef < camX.z) continue; depthRef = camX.z; - confMap(xRef) = depthData.confMap(x); + if (bAdjust) + confMap(xRef) = depthData.confMap(x); #else // set depth on the 4 pixels around the image projection const Point2 imgX(cameraRef.TransformPointC2I(camX)); @@ -1097,16 +1099,16 @@ bool DepthMapsData::FilterDepthMapAdjust(DepthData& depthDataRef, const IndexArr ImageRef(CEIL2INT(imgX.x), FLOOR2INT(imgX.y)), ImageRef(CEIL2INT(imgX.x), CEIL2INT(imgX.y)) }; - const float conf(depthData.confMap(x)); for (int p=0; p<4; ++p) { const ImageRef& xRef = xRefs[p]; if (!depthMap.isInside(xRef)) continue; Depth& depthRef(depthMap(xRef)); - if (depthRef != 0 && depthRef < (float)camX.z) + if (depthRef != 0 && depthRef < (Depth)camX.z) continue; - depthRef = (float)camX.z; - confMap(xRef) = conf; + depthRef = (Depth)camX.z; + if (bAdjust) + confMap(xRef) = depthData.confMap(x); } #endif } @@ -1117,79 +1119,160 @@ bool DepthMapsData::FilterDepthMapAdjust(DepthData& depthDataRef, const IndexArr #endif } - // average similar depths, and decrease confidence if depths do not agree - const float thDepthDiff(OPTDENSE::fDepthDiffThreshold*1.4f); + const float thDepthDiff(OPTDENSE::fDepthDiffThreshold*1.2f); DepthMap newDepthMap(sizeRef); ConfidenceMap newConfMap(sizeRef); #if TD_VERBOSE != TD_VERBOSE_OFF size_t nProcessed(0), nDiscarded(0); #endif - for (int i=0; i 0); - #if TD_VERBOSE != TD_VERBOSE_OFF - ++nProcessed; - #endif - // update best depth and confidence estimate with all estimates - float posConf(depthDataRef.confMap(xRef)), negConf(0); - Depth avgDepth(depth*posConf); - unsigned nPosViews(0), nNegViews(0); - unsigned n(N); - do { - const Depth d(depthMaps[--n](xRef)); - if (d == 0) { - if (nPosViews + nNegViews + n < nMinViews) - goto DiscardDepth; + if (bAdjust) { + // average similar depths, and decrease confidence if depths do not agree + // (inspired by: "Real-Time Visibility-Based Fusion of Depth Maps", Merrell, 2007) + for (int i=0; i 0); - if (IsDepthSimilar(depth, d, thDepthDiff)) { - // average similar depths - const float c(confMaps[n](xRef)); - avgDepth += d*c; - posConf += c; - ++nPosViews; - } else { - // penalize confidence - if (depth > d) { - // occlusion - negConf += confMaps[n](xRef); + ASSERT(depth > 0); + #if TD_VERBOSE != TD_VERBOSE_OFF + ++nProcessed; + #endif + // update best depth and confidence estimate with all estimates + float posConf(depthDataRef.confMap(xRef)), negConf(0); + Depth avgDepth(depth*posConf); + unsigned nPosViews(0), nNegViews(0); + unsigned n(N); + do { + const Depth d(depthMaps[--n](xRef)); + if (d == 0) { + if (nPosViews + nNegViews + n < nMinViews) + goto DiscardDepth; + continue; + } + ASSERT(d > 0); + if (IsDepthSimilar(depth, d, thDepthDiff)) { + // average similar depths + const float c(confMaps[n](xRef)); + avgDepth += d*c; + posConf += c; + ++nPosViews; } else { - // free-space violation - const DepthData& depthData = arrDepthData[depthDataRef.neighbors[idxNeighbors[n]].idx.ID]; - const Camera& camera = depthData.images.First().camera; - const Point3 X(cameraRef.TransformPointI2W(Point3(xRef.x,xRef.y,depth))); - const ImageRef x(ROUND2INT(camera.TransformPointW2I(X))); - if (depthData.confMap.isInside(x)) { - const float c(depthData.confMap(x)); - negConf += (c > 0 ? c : confMaps[n](xRef)); - } else + // penalize confidence + if (depth > d) { + // occlusion negConf += confMaps[n](xRef); + } else { + // free-space violation + const DepthData& depthData = arrDepthData[depthDataRef.neighbors[idxNeighbors[n]].idx.ID]; + const Camera& camera = depthData.images.First().camera; + const Point3 X(cameraRef.TransformPointI2W(Point3(xRef.x,xRef.y,depth))); + const ImageRef x(ROUND2INT(camera.TransformPointW2I(X))); + if (depthData.confMap.isInside(x)) { + const float c(depthData.confMap(x)); + negConf += (c > 0 ? c : confMaps[n](xRef)); + } else + negConf += confMaps[n](xRef); + } + ++nNegViews; } - ++nNegViews; + } while (n); + ASSERT(nPosViews+nNegViews >= nMinViews); + // if enough good views and positive confidence... + if (nPosViews >= nMinViewsAdjust && posConf > negConf && ISINSIDE(avgDepth/=posConf, depthDataRef.dMin, depthDataRef.dMax)) { + // consider this pixel an inlier + newDepthMap(xRef) = avgDepth; + newConfMap(xRef) = posConf - negConf; + } else { + // consider this pixel an outlier + DiscardDepth: + newDepthMap(xRef) = 0; + newConfMap(xRef) = 0; + #if TD_VERBOSE != TD_VERBOSE_OFF + ++nDiscarded; + #endif } - } while (n); - ASSERT(nPosViews+nNegViews >= nMinViews); - // if enough good views and positive confidence... - if (nPosViews >= nMinViewsAdjust && posConf > negConf && ISINSIDE(avgDepth/=posConf, depthDataRef.dMin, depthDataRef.dMax)) { - // consider this pixel an inlier - newDepthMap(xRef) = avgDepth; - newConfMap(xRef) = posConf - negConf; - } else { - // consider this pixel an outlier - DiscardDepth: - newDepthMap(xRef) = 0; - newConfMap(xRef) = 0; + } + } + } else { + // remove depth if it does not agree with enough neighbors + const float thDepthDiffStrict(OPTDENSE::fDepthDiffThreshold*0.8f); + const unsigned nMinGoodViewsProc(75), nMinGoodViewsDeltaProc(65); + const unsigned nDeltas(4); + const unsigned nMinViewsDelta(nMinViews*(nDeltas-2)); + const ImageRef xDs[nDeltas] = { ImageRef(-1,0), ImageRef(1,0), ImageRef(0,-1), ImageRef(0,1) }; + for (int i=0; i 0); #if TD_VERBOSE != TD_VERBOSE_OFF - ++nDiscarded; + ++nProcessed; #endif + // check if very similar with the neighbors projected to this pixel + { + unsigned nGoodViews(0); + unsigned nViews(0); + unsigned n(N); + do { + const Depth d(depthMaps[--n](xRef)); + if (d > 0) { + // valid view + ++nViews; + if (IsDepthSimilar(depth, d, thDepthDiffStrict)) { + // agrees with this neighbor + ++nGoodViews; + } + } + } while (n); + if (nGoodViews < nMinViews || nGoodViews < nViews*nMinGoodViewsProc/100) { + #if TD_VERBOSE != TD_VERBOSE_OFF + ++nDiscarded; + #endif + newDepthMap(xRef) = 0; + newConfMap(xRef) = 0; + continue; + } + } + // check if similar with the neighbors projected around this pixel + { + unsigned nGoodViews(0); + unsigned nViews(0); + for (unsigned d=0; d 0) { + // valid view + ++nViews; + if (IsDepthSimilar(depth, d, thDepthDiff)) { + // agrees with this neighbor + ++nGoodViews; + } + } + } while (n); + } + if (nGoodViews < nMinViewsDelta || nGoodViews < nViews*nMinGoodViewsDeltaProc/100) { + #if TD_VERBOSE != TD_VERBOSE_OFF + ++nDiscarded; + #endif + newDepthMap(xRef) = 0; + newConfMap(xRef) = 0; + continue; + } + } + // enough good views, keep it + newDepthMap(xRef) = depth; + newConfMap(xRef) = depthDataRef.confMap(xRef); } } } @@ -1202,7 +1285,7 @@ bool DepthMapsData::FilterDepthMapAdjust(DepthData& depthDataRef, const IndexArr #endif return true; -} // FilterDepthMapAdjust +} // FilterDepthMap /*----------------------------------------------------------------*/ // fuse all valid depth-maps in the same 3D point cloud; @@ -1222,7 +1305,7 @@ struct Proj { }; typedef SEACAVE::cList ProjArr; typedef SEACAVE::cList ProjsArr; -void DepthMapsData::FuseFilterDepthMaps(PointCloud& pointcloud, bool bEstimateNormal) +void DepthMapsData::FuseDepthMaps(PointCloud& pointcloud, bool bEstimateNormal) { TD_TIMER_STARTD(); @@ -1385,7 +1468,7 @@ void DepthMapsData::FuseFilterDepthMaps(PointCloud& pointcloud, bool bEstimateNo if (pDepthData->IsValid()) pDepthData->DecRef(); } -} // FuseFilterDepthMaps +} // FuseDepthMaps /*----------------------------------------------------------------*/ @@ -1545,7 +1628,7 @@ bool Scene::DenseReconstruction() // fuse all depth-maps pointcloud.Release(); - data.detphMaps.FuseFilterDepthMaps(pointcloud, OPTDENSE::nEstimateNormals == 2); + data.detphMaps.FuseDepthMaps(pointcloud, OPTDENSE::nEstimateNormals == 2); #if TD_VERBOSE != TD_VERBOSE_OFF if (g_nVerbosityLevel > 2) { // print number of points with 3+ views @@ -1739,7 +1822,7 @@ void Scene::DenseReconstructionFilter(void* pData) break; } // filter the depth-map for this image - if (data.detphMaps.FilterDepthMapAdjust(depthData, idxNeighbors)) { + if (data.detphMaps.FilterDepthMap(depthData, idxNeighbors, OPTDENSE::bFilterAdjust)) { // load the filtered maps after all depth-maps were filtered data.events.AddEvent(new EVTAdjustDepthMap(evtImage.idxImage)); } diff --git a/libs/MVS/SceneReconstruct.cpp b/libs/MVS/SceneReconstruct.cpp index 4b10f1dfc..ef957941a 100644 --- a/libs/MVS/SceneReconstruct.cpp +++ b/libs/MVS/SceneReconstruct.cpp @@ -97,7 +97,7 @@ class MaxFlow return graph.isNodeOnSrcSide((int)n); } -private: +protected: graph_type graph; }; #else @@ -180,7 +180,7 @@ class MaxFlow return (color[n] != boost::white_color); } -private: +protected: graph_type graph; std::vector color; const node_type S; diff --git a/libs/MVS/SceneRefine.cpp b/libs/MVS/SceneRefine.cpp index 815ea1327..ff0755fae 100644 --- a/libs/MVS/SceneRefine.cpp +++ b/libs/MVS/SceneRefine.cpp @@ -251,9 +251,7 @@ TYPE* MeshRefine::TypePool(TYPE* pObj) if (pObj == NULL) { if (unused.IsEmpty()) return objects.AddConstruct(new TYPE); - pObj = unused.Last(); - unused.RemoveLast(); - return pObj; + return unused.RemoveTail(); } else { ASSERT(objects.Find(pObj) != NO_IDX); ASSERT(unused.Find(pObj) == NO_IDX); diff --git a/libs/MVS/SceneTexture.cpp b/libs/MVS/SceneTexture.cpp index 5f8db94ac..78cffbb8f 100644 --- a/libs/MVS/SceneTexture.cpp +++ b/libs/MVS/SceneTexture.cpp @@ -417,7 +417,7 @@ struct MeshTexture { } -private: +protected: static void ProcessMask(Image8U& mask, int stripWidth); static void PoissonBlending(const Image32F3& src, Image32F3& dst, const Image8U& mask, float bias=1.f); diff --git a/libs/Math/LBP.h b/libs/Math/LBP.h index 2a910e299..f3e7fd1c0 100644 --- a/libs/Math/LBP.h +++ b/libs/Math/LBP.h @@ -46,7 +46,7 @@ class LBPInference enum { MaxEnergy = 1000 }; -private: +protected: struct DirectedEdge { NodeID nodeID1; NodeID nodeID2;