diff --git a/apps/InterfaceOpenMVG/InterfaceOpenMVG.cpp b/apps/InterfaceOpenMVG/InterfaceOpenMVG.cpp index 02af483f6..2e9d95317 100644 --- a/apps/InterfaceOpenMVG/InterfaceOpenMVG.cpp +++ b/apps/InterfaceOpenMVG/InterfaceOpenMVG.cpp @@ -1,9 +1,7 @@ /* * InterfaceOpenMVG.cpp * - * Copyright (c) 2014-2015 FOXEL SA - http://foxel.ch - * Please read for more information. - * + * Copyright (c) 2014-2015 SEACAVE * * Author(s): * @@ -11,8 +9,6 @@ * Pierre MOULON * * - * This file is part of the FOXEL project . - * * 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 @@ -32,9 +28,6 @@ * You are required to preserve legal notices and author attributions in * that material or in the Appropriate Legal Notices displayed by works * containing it. - * - * You are required to attribute the work as explained in the "Usage and - * Attribution" section of . */ #include "../../libs/MVS/Common.h" diff --git a/apps/InterfaceOpenMVG/InterfaceOpenMVG2.cpp b/apps/InterfaceOpenMVG/InterfaceOpenMVG2.cpp index 6413b33b4..f0191e0cd 100644 --- a/apps/InterfaceOpenMVG/InterfaceOpenMVG2.cpp +++ b/apps/InterfaceOpenMVG/InterfaceOpenMVG2.cpp @@ -1,9 +1,7 @@ /* * InterfaceOpenMVG.cpp * - * Copyright (c) 2014-2015 FOXEL SA - http://foxel.ch - * Please read for more information. - * + * Copyright (c) 2014-2015 SEACAVE * * Author(s): * @@ -11,8 +9,6 @@ * Pierre MOULON * * - * This file is part of the FOXEL project . - * * 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 @@ -32,9 +28,6 @@ * You are required to preserve legal notices and author attributions in * that material or in the Appropriate Legal Notices displayed by works * containing it. - * - * You are required to attribute the work as explained in the "Usage and - * Attribution" section of . */ #include "../../libs/MVS/Common.h" diff --git a/apps/ReconstructMesh/ReconstructMesh.cpp b/apps/ReconstructMesh/ReconstructMesh.cpp index f1acf9e14..30cf8fe9b 100644 --- a/apps/ReconstructMesh/ReconstructMesh.cpp +++ b/apps/ReconstructMesh/ReconstructMesh.cpp @@ -1,17 +1,13 @@ /* * ReconstructMesh.cpp * - * Copyright (c) 2014-2015 FOXEL SA - http://foxel.ch - * Please read for more information. - * + * Copyright (c) 2014-2015 SEACAVE * * Author(s): * * cDc * * - * This file is part of the FOXEL project . - * * 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 @@ -31,9 +27,6 @@ * You are required to preserve legal notices and author attributions in * that material or in the Appropriate Legal Notices displayed by works * containing it. - * - * You are required to attribute the work as explained in the "Usage and - * Attribution" section of . */ #include "../../libs/MVS/Common.h" diff --git a/libs/Common/AutoPtr.h b/libs/Common/AutoPtr.h index 5c4a2b4ab..ab9a537b0 100644 --- a/libs/Common/AutoPtr.h +++ b/libs/Common/AutoPtr.h @@ -113,22 +113,12 @@ class CAutoPtr return m_pointer; } - inline bool operator==(const CAutoPtr& _Right) const - { // return pointer to class object - return (m_pointer == _Right.m_pointer); - } - - inline bool operator!=(const CAutoPtr& _Right) const - { // return pointer to class object - return (m_pointer != _Right.m_pointer); - } - - inline bool operator==(const void* _Right) const + inline bool operator==(const TypePtr _Right) const { // return pointer to class object return (m_pointer == _Right); } - inline bool operator!=(const void* _Right) const + inline bool operator!=(const TypePtr _Right) const { // return pointer to class object return (m_pointer != _Right); } @@ -237,22 +227,12 @@ class CAutoPtrArr return m_pointer; } - inline bool operator==(const CAutoPtrArr& _Right) const - { // return pointer to class object - return (m_pointer == _Right.m_pointer); - } - - inline bool operator!=(const CAutoPtrArr& _Right) const - { // return pointer to class object - return (m_pointer != _Right.m_pointer); - } - - inline bool operator==(const void* _Right) const + inline bool operator==(const TypePtr _Right) const { // return pointer to class object return (m_pointer == _Right); } - inline bool operator!=(const void* _Right) const + inline bool operator!=(const TypePtr _Right) const { // return pointer to class object return (m_pointer != _Right); } diff --git a/libs/MVS/Camera.cpp b/libs/MVS/Camera.cpp index c8d945530..e8d7d5e0c 100644 --- a/libs/MVS/Camera.cpp +++ b/libs/MVS/Camera.cpp @@ -1,17 +1,13 @@ /* * Camera.cpp * -* Copyright (c) 2014-2015 FOXEL SA - http://foxel.ch -* Please read for more information. -* +* Copyright (c) 2014-2015 SEACAVE * * Author(s): * * cDc * * -* This file is part of the FOXEL project . -* * 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 @@ -31,9 +27,6 @@ * You are required to preserve legal notices and author attributions in * that material or in the Appropriate Legal Notices displayed by works * containing it. -* -* You are required to attribute the work as explained in the "Usage and -* Attribution" section of . */ #include "Common.h" diff --git a/libs/MVS/Camera.h b/libs/MVS/Camera.h index daa43204e..56dd88073 100644 --- a/libs/MVS/Camera.h +++ b/libs/MVS/Camera.h @@ -1,17 +1,13 @@ /* * Camera.h * -* Copyright (c) 2014-2015 FOXEL SA - http://foxel.ch -* Please read for more information. -* +* Copyright (c) 2014-2015 SEACAVE * * Author(s): * * cDc * * -* This file is part of the FOXEL project . -* * 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 @@ -31,9 +27,6 @@ * You are required to preserve legal notices and author attributions in * that material or in the Appropriate Legal Notices displayed by works * containing it. -* -* You are required to attribute the work as explained in the "Usage and -* Attribution" section of . */ #ifndef _MVS_CAMERA_H_ diff --git a/libs/MVS/Common.cpp b/libs/MVS/Common.cpp index c099c3937..ac3a71c19 100644 --- a/libs/MVS/Common.cpp +++ b/libs/MVS/Common.cpp @@ -1,17 +1,13 @@ /* * Common.cpp * -* Copyright (c) 2014-2015 FOXEL SA - http://foxel.ch -* Please read for more information. -* +* Copyright (c) 2014-2015 SEACAVE * * Author(s): * * cDc * * -* This file is part of the FOXEL project . -* * 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 @@ -31,9 +27,6 @@ * You are required to preserve legal notices and author attributions in * that material or in the Appropriate Legal Notices displayed by works * containing it. -* -* You are required to attribute the work as explained in the "Usage and -* Attribution" section of . */ // Source file that includes just the standard includes diff --git a/libs/MVS/Common.h b/libs/MVS/Common.h index 64e083c9d..f718f44a5 100644 --- a/libs/MVS/Common.h +++ b/libs/MVS/Common.h @@ -1,17 +1,13 @@ /* * Common.h * -* Copyright (c) 2014-2015 FOXEL SA - http://foxel.ch -* Please read for more information. -* +* Copyright (c) 2014-2015 SEACAVE * * Author(s): * * cDc * * -* This file is part of the FOXEL project . -* * 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 @@ -31,9 +27,6 @@ * You are required to preserve legal notices and author attributions in * that material or in the Appropriate Legal Notices displayed by works * containing it. -* -* You are required to attribute the work as explained in the "Usage and -* Attribution" section of . */ #ifndef _MVS_COMMON_H_ diff --git a/libs/MVS/Image.cpp b/libs/MVS/Image.cpp index d17e1144b..e83a75d67 100644 --- a/libs/MVS/Image.cpp +++ b/libs/MVS/Image.cpp @@ -1,17 +1,13 @@ /* * Image.cpp * -* Copyright (c) 2014-2015 FOXEL SA - http://foxel.ch -* Please read for more information. -* +* Copyright (c) 2014-2015 SEACAVE * * Author(s): * * cDc * * -* This file is part of the FOXEL project . -* * 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 @@ -31,9 +27,6 @@ * You are required to preserve legal notices and author attributions in * that material or in the Appropriate Legal Notices displayed by works * containing it. -* -* You are required to attribute the work as explained in the "Usage and -* Attribution" section of . */ #include "Common.h" diff --git a/libs/MVS/Image.h b/libs/MVS/Image.h index 4e6cf3e24..1f7ba9f7e 100644 --- a/libs/MVS/Image.h +++ b/libs/MVS/Image.h @@ -1,17 +1,13 @@ /* * Image.h * -* Copyright (c) 2014-2015 FOXEL SA - http://foxel.ch -* Please read for more information. -* +* Copyright (c) 2014-2015 SEACAVE * * Author(s): * * cDc * * -* This file is part of the FOXEL project . -* * 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 @@ -31,9 +27,6 @@ * You are required to preserve legal notices and author attributions in * that material or in the Appropriate Legal Notices displayed by works * containing it. -* -* You are required to attribute the work as explained in the "Usage and -* Attribution" section of . */ #ifndef _MVS_VIEW_H_ diff --git a/libs/MVS/Platform.cpp b/libs/MVS/Platform.cpp index 7b3319f68..b3480c5f1 100644 --- a/libs/MVS/Platform.cpp +++ b/libs/MVS/Platform.cpp @@ -1,17 +1,13 @@ /* * Platform.cpp * -* Copyright (c) 2014-2015 FOXEL SA - http://foxel.ch -* Please read for more information. -* +* Copyright (c) 2014-2015 SEACAVE * * Author(s): * * cDc * * -* This file is part of the FOXEL project . -* * 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 @@ -31,9 +27,6 @@ * You are required to preserve legal notices and author attributions in * that material or in the Appropriate Legal Notices displayed by works * containing it. -* -* You are required to attribute the work as explained in the "Usage and -* Attribution" section of . */ #include "Common.h" diff --git a/libs/MVS/Platform.h b/libs/MVS/Platform.h index 4c3bfe492..a0f9499c3 100644 --- a/libs/MVS/Platform.h +++ b/libs/MVS/Platform.h @@ -1,17 +1,13 @@ /* * Platform.h * -* Copyright (c) 2014-2015 FOXEL SA - http://foxel.ch -* Please read for more information. -* +* Copyright (c) 2014-2015 SEACAVE * * Author(s): * * cDc * * -* This file is part of the FOXEL project . -* * 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 @@ -31,9 +27,6 @@ * You are required to preserve legal notices and author attributions in * that material or in the Appropriate Legal Notices displayed by works * containing it. -* -* You are required to attribute the work as explained in the "Usage and -* Attribution" section of . */ #ifndef _MVS_PLATFORM_H_ diff --git a/libs/MVS/PointCloud.cpp b/libs/MVS/PointCloud.cpp index 3ad8ca7b9..e7c53083b 100644 --- a/libs/MVS/PointCloud.cpp +++ b/libs/MVS/PointCloud.cpp @@ -1,17 +1,13 @@ /* * PointCloud.cpp * -* Copyright (c) 2014-2015 FOXEL SA - http://foxel.ch -* Please read for more information. -* +* Copyright (c) 2014-2015 SEACAVE * * Author(s): * * cDc * * -* This file is part of the FOXEL project . -* * 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 @@ -31,9 +27,6 @@ * You are required to preserve legal notices and author attributions in * that material or in the Appropriate Legal Notices displayed by works * containing it. -* -* You are required to attribute the work as explained in the "Usage and -* Attribution" section of . */ #include "Common.h" diff --git a/libs/MVS/PointCloud.h b/libs/MVS/PointCloud.h index ccff07603..27cd8cd67 100644 --- a/libs/MVS/PointCloud.h +++ b/libs/MVS/PointCloud.h @@ -1,17 +1,13 @@ /* * PointCloud.h * -* Copyright (c) 2014-2015 FOXEL SA - http://foxel.ch -* Please read for more information. -* +* Copyright (c) 2014-2015 SEACAVE * * Author(s): * * cDc * * -* This file is part of the FOXEL project . -* * 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 @@ -31,9 +27,6 @@ * You are required to preserve legal notices and author attributions in * that material or in the Appropriate Legal Notices displayed by works * containing it. -* -* You are required to attribute the work as explained in the "Usage and -* Attribution" section of . */ #ifndef _MVS_POINTCLOUD_H_ diff --git a/libs/MVS/SceneReconstruct.cpp b/libs/MVS/SceneReconstruct.cpp index 4fd3c9a31..4b10f1dfc 100644 --- a/libs/MVS/SceneReconstruct.cpp +++ b/libs/MVS/SceneReconstruct.cpp @@ -1,17 +1,13 @@ /* * SceneReconstruct.cpp * -* Copyright (c) 2014-2015 FOXEL SA - http://foxel.ch -* Please read for more information. -* +* Copyright (c) 2014-2015 SEACAVE * * Author(s): * * cDc * * -* This file is part of the FOXEL project . -* * 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 @@ -31,9 +27,6 @@ * You are required to preserve legal notices and author attributions in * that material or in the Appropriate Legal Notices displayed by works * containing it. -* -* You are required to attribute the work as explained in the "Usage and -* Attribution" section of . */ #include "Common.h" diff --git a/libs/MVS/SceneRefine.cpp b/libs/MVS/SceneRefine.cpp index 602a76221..2e63032a5 100644 --- a/libs/MVS/SceneRefine.cpp +++ b/libs/MVS/SceneRefine.cpp @@ -45,6 +45,22 @@ using namespace MVS; // (should be enough, as the numerical error does not depend on the depth) #define MESHOPT_DEPTHCONSTBIAS 0.05f +// uncomment to use enable memory pool +// (should reduce the allocation times for frequent used images) +#define MESHOPT_TYPEPOOL + +#ifdef MESHOPT_TYPEPOOL +#define DEC_BitMatrix(var) BitMatrix& var = *BitMatrixPool() +#define DEC_Image(type, var) TImage& var = *ImagePool() +#define DST_BitMatrix(var) BitMatrixPool(&(var)) +#define DST_Image(var) ImagePool(&(var)) +#else +#define DEC_BitMatrix(var) BitMatrix var; +#define DEC_Image(type, var) TImage var; +#define DST_BitMatrix(var) +#define DST_Image(var) +#endif + // S T R U C T S /////////////////////////////////////////////////// @@ -162,6 +178,11 @@ class MeshRefine { static void ComputeSmoothnessGradient2( const GradArr& smoothGrad1, const Mesh::VertexVerticesArr& vertexVertices, const BoolArr& vertexBoundary, GradArr& smoothGrad2, VIndex idxStart, VIndex idxEnd); + template + static TYPE* TypePool(TYPE* = NULL); + template + static inline TImage* ImagePool(TImage* pImage = NULL) { return TypePool< TImage >(pImage); } + static inline BitMatrix* BitMatrixPool(BitMatrix* pMask = NULL) { return TypePool(pMask); } static void* ThreadWorkerTmp(void*); void ThreadWorker(); @@ -217,6 +238,30 @@ class MeshRefine { static const int HalfSize = 3; // half window size used to compute ZNCC }; +// call with empty parameter to get an unused image; +// call with an image pointer retrieved earlier to signal that is not needed anymore +template +static TYPE* MeshRefine::TypePool(TYPE* pObj) +{ + typedef CAutoPtr TypePtr; + static CriticalSection cs; + static cList objects; + static cList unused; + Lock l(cs); + if (pObj == NULL) { + if (unused.IsEmpty()) + return objects.AddConstruct(new TYPE); + pObj = unused.Last(); + unused.RemoveLast(); + return pObj; + } else { + ASSERT(objects.Find(pObj) != NO_IDX); + ASSERT(unused.Find(pObj) == NO_IDX); + unused.Insert(pObj); + return NULL; + } +} + enum EVENT_TYPE { EVT_JOB = 0, @@ -801,7 +846,8 @@ void MeshRefine::ComputeLocalVariance(const Image32F& image, const BitMatrix& ma const int RowsEnd(image.rows-HalfSize); const int ColsEnd(image.cols-HalfSize); const int n(SQUARE(HalfSize*2+1)); - Image64F imageSum, imageSumSq; + DEC_Image(double, imageSum); + DEC_Image(double, imageSumSq); #if CV_MAJOR_VERSION > 2 cv::integral(image, imageSum, imageSumSq, CV_64F, CV_64F); #else @@ -818,6 +864,7 @@ void MeshRefine::ComputeLocalVariance(const Image32F& image, const BitMatrix& ma imageSum(r-HalfSize, c-HalfSize ) ) * (1.0/(double)n)); } } + DST_Image(imageSum); for (int r=HalfSize; r imageInvSqrtVAVB(mask.size()); + DEC_Image(double, imageABSum); + { + DEC_Image(float, imageAB); + cv::multiply(imageA, imageB, imageAB); + cv::integral(imageAB, imageABSum, CV_64F); + DST_Image(imageAB); + } + DEC_Image(Real, imageInvSqrtVAVB); + imageInvSqrtVAVB.create(mask.size()); for (int r=HalfSize; r imageMeanA, imageVarA; - if (nReduceMemory) - ComputeLocalVariance(viewA.image, mask, imageMeanA, imageVarA); - else - imageMeanA = viewA.imageMean, imageVarA = viewA.imageVar; - TImage imageMeanAB, imageVarAB; + const TImage *imageMeanA, *imageVarA; + if (nReduceMemory) { + DEC_Image(Real, _imageMeanA); + DEC_Image(Real, _imageVarA); + ComputeLocalVariance(viewA.image, mask, _imageMeanA, _imageVarA); + imageMeanA = &_imageMeanA; + imageVarA = &_imageVarA; + } else { + imageMeanA = &viewA.imageMean; + imageVarA = &viewA.imageVar; + } + DEC_Image(Real, imageMeanAB); + DEC_Image(Real, imageVarAB); ComputeLocalVariance(imageAB, mask, imageMeanAB, imageVarAB); - TImage imageZNCC, imageDZNCC; - const float score(ComputeLocalZNCC(imageA, imageMeanA, imageVarA, imageAB, imageMeanAB, imageVarAB, mask, imageZNCC, imageDZNCC)); + DEC_Image(Real, imageZNCC); + DEC_Image(Real, imageDZNCC); + const float score(ComputeLocalZNCC(imageA, *imageMeanA, *imageVarA, imageAB, imageMeanAB, imageVarAB, mask, imageZNCC, imageDZNCC)); + #ifdef MESHOPT_TYPEPOOL + DST_Image(imageZNCC); + DST_Image(imageVarAB); + DST_Image(imageMeanAB); + if (nReduceMemory) { + DST_Image(*((TImage*)imageMeanA)); + DST_Image(*((TImage*)imageVarA)); + } + DST_Image(imageAB); + #endif // compute field gradient GradArr _photoGrad(photoGrad.GetSize()); UnsignedArr _photoGradNorm(photoGrad.GetSize()); const Real RegularizationScale((Real)((REAL)(imageDataA.avgDepth*imageDataB.avgDepth)/(cameraA.GetFocalLength()*cameraB.GetFocalLength()))); ComputePhotometricGradient(faces, faceNormals, depthMapA, faceMapA, baryMapA, cameraA, cameraB, viewB, imageDZNCC, mask, _photoGrad, _photoGradNorm, RegularizationScale); + DST_Image(imageDZNCC); + DST_BitMatrix(mask); Lock l(cs); if (vertexDepth.IsEmpty()) { FOREACH(i, photoGrad) {