From 212ce5c8ac3b46fc98aded045536f79227f5a407 Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Thu, 19 Mar 2026 11:26:35 +0100 Subject: [PATCH] [Sofa.Helper] Fix a few warnings --- .../Helper/src/sofa/helper/AdvancedTimer.cpp | 22 +-- .../Helper/src/sofa/helper/BackTrace.cpp | 2 +- .../Helper/src/sofa/helper/DiffLib.cpp | 20 +-- .../Helper/src/sofa/helper/LCPcalc.cpp | 56 +++---- .../src/sofa/helper/MarchingCubeUtility.cpp | 150 +++++++++--------- .../src/sofa/helper/MarchingCubeUtility.h | 58 +++---- .../Helper/src/sofa/helper/OptionsGroup.cpp | 7 +- .../src/sofa/helper/RandomGenerator.cpp | 4 +- .../Helper/src/sofa/helper/RandomGenerator.h | 4 +- .../Helper/src/sofa/helper/TriangleOctree.cpp | 23 +-- .../Helper/src/sofa/helper/io/Image.cpp | 69 ++++---- .../Helper/src/sofa/helper/io/Image.h | 8 +- .../src/sofa/helper/system/FileSystem.cpp | 5 +- 13 files changed, 219 insertions(+), 209 deletions(-) diff --git a/Sofa/framework/Helper/src/sofa/helper/AdvancedTimer.cpp b/Sofa/framework/Helper/src/sofa/helper/AdvancedTimer.cpp index 1d9ba5308b0..3bf86905226 100644 --- a/Sofa/framework/Helper/src/sofa/helper/AdvancedTimer.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/AdvancedTimer.cpp @@ -56,7 +56,7 @@ template class SOFA_HELPER_API AdvancedTimer::Id; class TimerData { public: - AdvancedTimer::IdTimer id; + AdvancedTimer::IdTimer m_id; type::vector records; int nbIter; int interval; @@ -89,7 +89,7 @@ class TimerData void init(AdvancedTimer::IdTimer id) { - this->id = id; + this->m_id = id; const std::string envvar = std::string("SOFA_TIMER_") + (std::string)id; const char* val = getenv(envvar.c_str()); if (!val || !*val) @@ -174,7 +174,7 @@ void AdvancedTimer::clear() bool AdvancedTimer::isEnabled(IdTimer id) { TimerData& data = timers[id]; - if (!data.id) + if (!data.m_id) { data.init(id); } @@ -184,7 +184,7 @@ bool AdvancedTimer::isEnabled(IdTimer id) void AdvancedTimer::setEnabled(IdTimer id, bool val) { TimerData& data = timers[id]; - if (!data.id) + if (!data.m_id) { data.init(id); } @@ -197,7 +197,7 @@ void AdvancedTimer::setEnabled(IdTimer id, bool val) int AdvancedTimer::getInterval(IdTimer id) { TimerData& data = timers[id]; - if (!data.id) + if (!data.m_id) { data.init(id); } @@ -207,7 +207,7 @@ int AdvancedTimer::getInterval(IdTimer id) void AdvancedTimer::setInterval(IdTimer id, int val) { TimerData& data = timers[id]; - if (!data.id) + if (!data.m_id) { data.init(id); } @@ -220,7 +220,7 @@ void AdvancedTimer::begin(IdTimer id) std::stack& curTimer = getCurTimer(); curTimer.push(id); TimerData& data = timers[curTimer.top()]; - if (!data.id) + if (!data.m_id) { data.init(id); } @@ -339,7 +339,7 @@ void AdvancedTimer::end(IdTimer id) std::string AdvancedTimer::end(IdTimer id, double time, double dt) { const TimerData& data = timers[id]; - if(!data.id) + if(!data.m_id) { return std::string(""); } @@ -801,7 +801,7 @@ void TimerData::print() { static ctime_t tmargin = CTime::getTicksPerSec() / 100000; std::ostream& out = std::cout; - out << "==== " << id << " ====\n\n"; + out << "==== " << m_id << " ====\n\n"; if (!records.empty()) { out << "Trace of last iteration :\n"; @@ -955,7 +955,7 @@ void AdvancedTimer::setOutputType(IdTimer id, const std::string& type) { // Seek for the timer TimerData& data = timers[id]; - if (!data.id) + if (!data.m_id) { data.init(id); } @@ -1101,7 +1101,7 @@ void TimerData::print(std::ostream& result) { //static ctime_t tmargin = CTime::getTicksPerSec() / 100000; std::ostream& out = result; - out << "Timer: " << id << "\n"; + out << "Timer: " << m_id << "\n"; if (!steps.empty()) { //out << "\nSteps Duration Statistics (in ms) :\n"; diff --git a/Sofa/framework/Helper/src/sofa/helper/BackTrace.cpp b/Sofa/framework/Helper/src/sofa/helper/BackTrace.cpp index 2bf58ab28f3..549ed6ec92b 100644 --- a/Sofa/framework/Helper/src/sofa/helper/BackTrace.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/BackTrace.cpp @@ -45,7 +45,7 @@ namespace sofa::helper { -BackTrace::StackTrace BackTrace::getTrace(size_t maxEntries) +BackTrace::StackTrace BackTrace::getTrace([[maybe_unused]] size_t maxEntries) { BackTrace::StackTrace result; diff --git a/Sofa/framework/Helper/src/sofa/helper/DiffLib.cpp b/Sofa/framework/Helper/src/sofa/helper/DiffLib.cpp index 86c121f455b..5bc31dd54db 100644 --- a/Sofa/framework/Helper/src/sofa/helper/DiffLib.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/DiffLib.cpp @@ -19,11 +19,13 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#include -#include #include #include +#include +#include +#include + namespace sofa::helper { @@ -35,27 +37,25 @@ std::vector> SOFA_HELPER_API getClosestMatch(cons { public: Tuple(float ratio_, std::string value_) - { - ratio = ratio_; - value = value_; - } + : ratio(ratio_), value(std::move(value_)) {} + float ratio; std::string value; }; - auto cmp = [](Tuple& left, Tuple& right) { return left.ratio < right.ratio; }; + auto cmp = [](const Tuple& left, Tuple& right) { return left.ratio < right.ratio; }; std::priority_queue, decltype(cmp)> q3(cmp); for(auto& s : haystack) { auto foo = difflib::MakeSequenceMatcher(needle,s); - q3.push(Tuple(foo.ratio(), s)); + q3.emplace(foo.ratio(), s); } std::vector> result; - while(!q3.empty() && result.size()<=numEntries) + while (!q3.empty() && result.size() <= numEntries) { if(q3.top().ratio < threshold) break; - result.push_back(std::make_tuple(q3.top().value, q3.top().ratio)); + result.emplace_back(q3.top().value, q3.top().ratio); q3.pop(); } return result; diff --git a/Sofa/framework/Helper/src/sofa/helper/LCPcalc.cpp b/Sofa/framework/Helper/src/sofa/helper/LCPcalc.cpp index 7e83d3a089f..30fe39bffdb 100644 --- a/Sofa/framework/Helper/src/sofa/helper/LCPcalc.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/LCPcalc.cpp @@ -1386,8 +1386,8 @@ int nlcp_multiGrid(int dim, SReal *dfree, SReal**W, SReal *f, SReal mu, SReal to free(d_coarse); free(d); - for (int i = 0; i < numContacts; i++) - delete W33[i]; + for (int c = 0; c < numContacts; c++) + delete W33[c]; free(W33); return 0; @@ -1525,10 +1525,10 @@ int nlcp_multiGrid(int dim, SReal *dfree, SReal**W, SReal *f, SReal mu, SReal to if(verbose) { - std::stringstream tmp; - tmp << "Result at the COARSE LEVEL: " << msgendl; - resultToString(tmp, F_coarse,num_group*3); - dmsg_info("LCPcalc") << tmp.str() ; + std::stringstream ss; + ss << "Result at the COARSE LEVEL: " << msgendl; + resultToString(ss, F_coarse,num_group*3); + dmsg_info("LCPcalc") << ss.str() ; } @@ -1551,10 +1551,10 @@ int nlcp_multiGrid(int dim, SReal *dfree, SReal**W, SReal *f, SReal mu, SReal to if(verbose) { - std::stringstream tmp; - tmp << "projection at the finer LEVEL: " << msgendl ; - resultToString(tmp, f,dim); - dmsg_info("LCPcalc") << tmp.str() ; + std::stringstream ss; + ss << "projection at the finer LEVEL: " << msgendl ; + resultToString(ss, f,dim); + dmsg_info("LCPcalc") << ss.str() ; } @@ -1564,10 +1564,10 @@ int nlcp_multiGrid(int dim, SReal *dfree, SReal**W, SReal *f, SReal mu, SReal to if(verbose) { - std::stringstream tmp; - tmp << "after 10 iteration at the finer LEVEL: " << msgendl ; - resultToString(tmp, f,dim); - dmsg_info("LCPcalc") << tmp.str(); + std::stringstream ss; + ss << "after 10 iteration at the finer LEVEL: " << msgendl ; + resultToString(ss, f,dim); + dmsg_info("LCPcalc") << ss.str(); } free(d_free_coarse); @@ -1576,8 +1576,8 @@ int nlcp_multiGrid(int dim, SReal *dfree, SReal**W, SReal *f, SReal mu, SReal to free(d_coarse); free(d); - for (int i = 0; i < numContacts; i++) - delete W33[i]; + for (int c = 0; c < numContacts; c++) + delete W33[c]; free(W33); return result; @@ -1679,9 +1679,9 @@ int nlcp_gaussseidel(int dim, SReal *dfree, SReal**W, SReal *f, SReal mu, SReal for (int c=0; c tdiff) { free(d); - for (int i = 0; i < numContacts; i++) - delete W33[i]; + for (int c = 0; c < numContacts; c++) + delete W33[c]; free(W33); return 1; } @@ -1830,8 +1830,8 @@ int nlcp_gaussseidelTimed(int dim, SReal *dfree, SReal**W, SReal*f, SReal mu, SR if (error < tol) { free(d); - for (int i = 0; i < numContacts; i++) - delete W33[i]; + for (int c = 0; c < numContacts; c++) + delete W33[c]; free(W33); sofa::helper::AdvancedTimer::valSet("GS iterations", it+1); return 1; @@ -1839,8 +1839,8 @@ int nlcp_gaussseidelTimed(int dim, SReal *dfree, SReal**W, SReal*f, SReal mu, SR } sofa::helper::AdvancedTimer::valSet("GS iterations", it); free(d); - for (int i = 0; i < numContacts; i++) - delete W33[i]; + for (int c = 0; c < numContacts; c++) + delete W33[c]; free(W33); if (verbose) diff --git a/Sofa/framework/Helper/src/sofa/helper/MarchingCubeUtility.cpp b/Sofa/framework/Helper/src/sofa/helper/MarchingCubeUtility.cpp index a2bfd7543b2..389a167f356 100644 --- a/Sofa/framework/Helper/src/sofa/helper/MarchingCubeUtility.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/MarchingCubeUtility.cpp @@ -371,9 +371,9 @@ namespace sofa::helper MarchingCubeUtility::MarchingCubeUtility() - : cubeStep ( 1 ), convolutionSize ( 1 ), - dataResolution ( 0,0,0 ), dataVoxelSize ( 1_sreal, 1_sreal, 1_sreal ), - verticesIndexOffset( 0), verticesTranslation( 0_sreal, 0_sreal, 0_sreal) + : m_cubeStep ( 1 ), m_convolutionSize ( 1 ), + m_dataResolution ( 0,0,0 ), m_dataVoxelSize ( 1_sreal, 1_sreal, 1_sreal ), + m_verticesIndexOffset( 0), m_verticesTranslation( 0_sreal, 0_sreal, 0_sreal) { // // Computes non trivial faces. // int nonTrivialFaces[256]; @@ -413,8 +413,8 @@ namespace sofa::helper { const float mu = ( isolevel - valp1 ) / ( valp2 - valp1 ); p = p1 + ( p2 - p1 ) * mu; - p = ( ( p + type::Vec3 ( 1_sreal, 1_sreal, 1_sreal) ) * 0.5_sreal ).linearProduct ( dataVoxelSize.linearProduct ( dataResolution ) ) + dataVoxelSize/2_sreal; - p += verticesTranslation; + p = ( ( p + type::Vec3 ( 1_sreal, 1_sreal, 1_sreal) ) * 0.5_sreal ).linearProduct ( m_dataVoxelSize.linearProduct ( m_dataResolution ) ) + m_dataVoxelSize/2_sreal; + p += m_verticesTranslation; p[0] = ( int ) helper::round( p[0] * (SReal)PRECISION ) / (SReal)PRECISION; p[1] = ( int ) helper::round( p[1] * (SReal)PRECISION ) / (SReal)PRECISION; p[2] = ( int ) helper::round( p[2] * (SReal)PRECISION ) / (SReal)PRECISION; @@ -434,37 +434,37 @@ namespace sofa::helper cell.pos[0]=vcurf.linearProduct ( gridStep )-type::Vec3 ( 1_sreal, 1_sreal, 1_sreal ); type::Vec3i valPos0=coord.linearProduct ( dataGridStep ); - cell.val[0]=(float)((( valPos0[0] >= roi.min[0]) && ( valPos0[1] >= roi.min[1]) && ( valPos0[2] >= roi.min[2]) && ( valPos0[0] < roi.max[0]) && ( valPos0[1] < roi.max[1]) && ( valPos0[2] < roi.max[2]))?data[valPos0[0] + valPos0[1]*dataResolution[0] + valPos0[2]*dataResolution[0]*dataResolution[1]]:0); + cell.val[0]=(float)((( valPos0[0] >= m_roi.min[0]) && ( valPos0[1] >= m_roi.min[1]) && ( valPos0[2] >= m_roi.min[2]) && ( valPos0[0] < m_roi.max[0]) && ( valPos0[1] < m_roi.max[1]) && ( valPos0[2] < m_roi.max[2]))?data[valPos0[0] + valPos0[1]*m_dataResolution[0] + valPos0[2]*m_dataResolution[0]*m_dataResolution[1]]:0); type::Vec3i valPos; cell.pos[1]=cell.pos[0]+type::Vec3 ( gridStep[0], 0_sreal, 0_sreal ); valPos=valPos0+type::Vec3i ( dataGridStep[0], 0, 0 ); - cell.val[1]=(float)((( valPos[0] >= roi.min[0]) && ( valPos[1] >= roi.min[1]) && ( valPos[2] >= roi.min[2]) && ( valPos[0] < roi.max[0]) && ( valPos[1] < roi.max[1]) && ( valPos[2] < roi.max[2]))?data[valPos[0] + valPos[1]*dataResolution[0] + valPos[2]*dataResolution[0]*dataResolution[1]]:0); + cell.val[1]=(float)((( valPos[0] >= m_roi.min[0]) && ( valPos[1] >= m_roi.min[1]) && ( valPos[2] >= m_roi.min[2]) && ( valPos[0] < m_roi.max[0]) && ( valPos[1] < m_roi.max[1]) && ( valPos[2] < m_roi.max[2]))?data[valPos[0] + valPos[1]*m_dataResolution[0] + valPos[2]*m_dataResolution[0]*m_dataResolution[1]]:0); cell.pos[2]=cell.pos[0]+type::Vec3 ( gridStep[0], gridStep[1], 0_sreal ); valPos=valPos0+type::Vec3i ( dataGridStep[0], dataGridStep[1], 0 ); - cell.val[2]=(float)((( valPos[0] >= roi.min[0]) && ( valPos[1] >= roi.min[1]) && ( valPos[2] >= roi.min[2]) && ( valPos[0] < roi.max[0]) && ( valPos[1] < roi.max[1]) && ( valPos[2] < roi.max[2]))?data[valPos[0] + valPos[1]*dataResolution[0] + valPos[2]*dataResolution[0]*dataResolution[1]]:0); + cell.val[2]=(float)((( valPos[0] >= m_roi.min[0]) && ( valPos[1] >= m_roi.min[1]) && ( valPos[2] >= m_roi.min[2]) && ( valPos[0] < m_roi.max[0]) && ( valPos[1] < m_roi.max[1]) && ( valPos[2] < m_roi.max[2]))?data[valPos[0] + valPos[1]*m_dataResolution[0] + valPos[2]*m_dataResolution[0]*m_dataResolution[1]]:0); cell.pos[3]=cell.pos[0]+type::Vec3 ( 0., gridStep[1], 0_sreal ); valPos=valPos0+type::Vec3i ( 0, dataGridStep[1], 0 ); - cell.val[3]=(float)((( valPos[0] >= roi.min[0]) && ( valPos[1] >= roi.min[1]) && ( valPos[2] >= roi.min[2]) && ( valPos[0] < roi.max[0]) && ( valPos[1] < roi.max[1]) && ( valPos[2] < roi.max[2]))?data[valPos[0] + valPos[1]*dataResolution[0] + valPos[2]*dataResolution[0]*dataResolution[1]]:0); + cell.val[3]=(float)((( valPos[0] >= m_roi.min[0]) && ( valPos[1] >= m_roi.min[1]) && ( valPos[2] >= m_roi.min[2]) && ( valPos[0] < m_roi.max[0]) && ( valPos[1] < m_roi.max[1]) && ( valPos[2] < m_roi.max[2]))?data[valPos[0] + valPos[1]*m_dataResolution[0] + valPos[2]*m_dataResolution[0]*m_dataResolution[1]]:0); cell.pos[4]=cell.pos[0]+type::Vec3 ( 0_sreal, 0_sreal, gridStep[2] ); valPos=valPos0+type::Vec3i ( 0, 0, dataGridStep[2] ); - cell.val[4]=(float)((( valPos[0] >= roi.min[0]) && ( valPos[1] >= roi.min[1]) && ( valPos[2] >= roi.min[2]) && ( valPos[0] < roi.max[0]) && ( valPos[1] < roi.max[1]) && ( valPos[2] < roi.max[2]))?data[valPos[0] + valPos[1]*dataResolution[0] + valPos[2]*dataResolution[0]*dataResolution[1]]:0); + cell.val[4]=(float)((( valPos[0] >= m_roi.min[0]) && ( valPos[1] >= m_roi.min[1]) && ( valPos[2] >= m_roi.min[2]) && ( valPos[0] < m_roi.max[0]) && ( valPos[1] < m_roi.max[1]) && ( valPos[2] < m_roi.max[2]))?data[valPos[0] + valPos[1]*m_dataResolution[0] + valPos[2]*m_dataResolution[0]*m_dataResolution[1]]:0); cell.pos[5]=cell.pos[0]+type::Vec3 ( gridStep[0], 0_sreal, gridStep[2] ); valPos=valPos0+type::Vec3i ( dataGridStep[0], 0, dataGridStep[2] ); - cell.val[5]=(float)((( valPos[0] >= roi.min[0]) && ( valPos[1] >= roi.min[1]) && ( valPos[2] >= roi.min[2]) && ( valPos[0] < roi.max[0]) && ( valPos[1] < roi.max[1]) && ( valPos[2] < roi.max[2]))?data[valPos[0] + valPos[1]*dataResolution[0] + valPos[2]*dataResolution[0]*dataResolution[1]]:0); + cell.val[5]=(float)((( valPos[0] >= m_roi.min[0]) && ( valPos[1] >= m_roi.min[1]) && ( valPos[2] >= m_roi.min[2]) && ( valPos[0] < m_roi.max[0]) && ( valPos[1] < m_roi.max[1]) && ( valPos[2] < m_roi.max[2]))?data[valPos[0] + valPos[1]*m_dataResolution[0] + valPos[2]*m_dataResolution[0]*m_dataResolution[1]]:0); cell.pos[6]=cell.pos[0]+type::Vec3 ( gridStep[0], gridStep[1], gridStep[2] ); valPos=valPos0+type::Vec3i ( dataGridStep[0], dataGridStep[1], dataGridStep[2] ); - cell.val[6]=(float)((( valPos[0] >= roi.min[0]) && ( valPos[1] >= roi.min[1]) && ( valPos[2] >= roi.min[2]) && ( valPos[0] < roi.max[0]) && ( valPos[1] < roi.max[1]) && ( valPos[2] < roi.max[2]))?data[valPos[0] + valPos[1]*dataResolution[0] + valPos[2]*dataResolution[0]*dataResolution[1]]:0); + cell.val[6]=(float)((( valPos[0] >= m_roi.min[0]) && ( valPos[1] >= m_roi.min[1]) && ( valPos[2] >= m_roi.min[2]) && ( valPos[0] < m_roi.max[0]) && ( valPos[1] < m_roi.max[1]) && ( valPos[2] < m_roi.max[2]))?data[valPos[0] + valPos[1]*m_dataResolution[0] + valPos[2]*m_dataResolution[0]*m_dataResolution[1]]:0); cell.pos[7]=cell.pos[0]+type::Vec3 ( 0_sreal, gridStep[1], gridStep[2] ); valPos=valPos0+type::Vec3i ( 0, dataGridStep[1], dataGridStep[2] ); - cell.val[7]=(float)((( valPos[0] >= roi.min[0]) && ( valPos[1] >= roi.min[1]) && ( valPos[2] >= roi.min[2]) && ( valPos[0] < roi.max[0]) && ( valPos[1] < roi.max[1]) && ( valPos[2] < roi.max[2]))?data[valPos[0] + valPos[1]*dataResolution[0] + valPos[2]*dataResolution[0]*dataResolution[1]]:0); + cell.val[7]=(float)((( valPos[0] >= m_roi.min[0]) && ( valPos[1] >= m_roi.min[1]) && ( valPos[2] >= m_roi.min[2]) && ( valPos[0] < m_roi.max[0]) && ( valPos[1] < m_roi.max[1]) && ( valPos[2] < m_roi.max[2]))?data[valPos[0] + valPos[1]*m_dataResolution[0] + valPos[2]*m_dataResolution[0]*m_dataResolution[1]]:0); } /* @@ -544,7 +544,7 @@ namespace sofa::helper else { //Add new Vertex in map - current_ID = static_cast(map_indices.size()) + verticesIndexOffset; + current_ID = static_cast(map_indices.size()) + m_verticesIndexOffset; map_indices.push_back ( current_P ); map_vertices.insert ( std::make_pair ( current_P, current_ID ) ); } @@ -575,21 +575,21 @@ namespace sofa::helper bool propagate ) const { - type::Vec3i bboxMin = type::Vec3i ( bbox.min / cubeStep ); - type::Vec3i bboxMax = type::Vec3i ( bbox.max / cubeStep ); - type::Vec3i gridSize = type::Vec3i ( dataResolution /cubeStep ); + type::Vec3i bboxMin = type::Vec3i ( m_bbox.min / m_cubeStep ); + type::Vec3i bboxMax = type::Vec3i ( m_bbox.max / m_cubeStep ); + type::Vec3i gridSize = type::Vec3i ( m_dataResolution /m_cubeStep ); const type::Vec3 gridStep { 2_sreal / static_cast(gridSize[0]), 2_sreal / static_cast(gridSize[1]), 2_sreal / static_cast(gridSize[2]) }; - const type::Vec3i dataGridStep ( dataResolution[0]/gridSize[0],dataResolution[1]/gridSize[1],dataResolution[2]/gridSize[2] ); + const type::Vec3i dataGridStep ( m_dataResolution[0]/gridSize[0],m_dataResolution[1]/gridSize[1],m_dataResolution[2]/gridSize[2] ); type::Vec3i cubeCoord; stack cubesToGenerate; // Stack of cubes to generate. for( sofa::type::vector::const_iterator it = coord.begin(); it != coord.end(); ++it) { const type::Vec3i& voxel = *it; - if ( ( voxel[0] >= bbox.min[0]-1 ) && ( voxel[1] >= bbox.min[1]-1 ) && ( voxel[2] >= bbox.min[2]-1 ) && - ( voxel[0] <= bbox.max[0] ) && ( voxel[1] <= bbox.max[1] ) && ( voxel[2] <= bbox.max[2] ) ) + if ( ( voxel[0] >= m_bbox.min[0]-1 ) && ( voxel[1] >= m_bbox.min[1]-1 ) && ( voxel[2] >= m_bbox.min[2]-1 ) && + ( voxel[0] <= m_bbox.max[0] ) && ( voxel[1] <= m_bbox.max[1] ) && ( voxel[2] <= m_bbox.max[2] ) ) cubesToGenerate.push ( *it ); // Adds the first non-trivial cube. } @@ -636,13 +636,13 @@ namespace sofa::helper // Vec3i gridSize = Vec3i ( d_dataResolution[0]/cubeStep, d_dataResolution[1]/cubeStep, d_dataResolution[2]/cubeStep ); std::set generatedCubes; - const size_t datasize = dataResolution[0]*dataResolution[1]*dataResolution[2]; + const size_t datasize = m_dataResolution[0]*m_dataResolution[1]*m_dataResolution[2]; if ( datasize == 0 ) return; unsigned char* data; bool smooth = false; - if ( convolutionSize != 0 ) + if ( m_convolutionSize != 0 ) { data = new unsigned char[datasize]; memcpy ( data, _data, datasize*sizeof ( unsigned char ) ); @@ -682,14 +682,14 @@ namespace sofa::helper sofa::type::vector< type::Vec3 >& vertices, type::vector< type::vector >* triangleIndexInRegularGrid ) const { - const size_t datasize = dataResolution[0]*dataResolution[1]*dataResolution[2]; + const size_t datasize = m_dataResolution[0]*m_dataResolution[1]*m_dataResolution[2]; if ( datasize == 0 ) return; unsigned char* data; bool smooth = false; - if ( convolutionSize != 0 ) + if ( m_convolutionSize != 0 ) { data = new unsigned char[datasize]; memcpy(data, _data, datasize*sizeof(unsigned char)); @@ -705,15 +705,15 @@ namespace sofa::helper for ( size_t i = 0; i < vertices.size(); i++ ) map_vertices.insert ( std::make_pair ( vertices[i], sofa::helper::narrow_cast(i) ) ); - type::Vec3i bboxMin = type::Vec3i ( bbox.min / cubeStep ); - type::Vec3i bboxMax = type::Vec3i ( bbox.max / cubeStep ); - type::Vec3i gridSize = type::Vec3i ( dataResolution /cubeStep ); + type::Vec3i bboxMin = type::Vec3i ( m_bbox.min / m_cubeStep ); + type::Vec3i bboxMax = type::Vec3i ( m_bbox.max / m_cubeStep ); + type::Vec3i gridSize = type::Vec3i ( m_dataResolution /m_cubeStep ); const type::Vec3 gridStep { 2_sreal / static_cast(gridSize[0]), 2_sreal / static_cast(gridSize[1]), 2_sreal / static_cast(gridSize[2]) }; - const type::Vec3i dataGridStep ( dataResolution[0]/gridSize[0],dataResolution[1]/gridSize[1],dataResolution[2]/gridSize[2] ); + const type::Vec3i dataGridStep ( m_dataResolution[0]/gridSize[0],m_dataResolution[1]/gridSize[1],m_dataResolution[2]/gridSize[2] ); int cubeConf; for ( int k=bboxMin[2]; k parsedVoxels; - const size_t datasize = dataResolution[0]*dataResolution[1]*dataResolution[2]; + const size_t datasize = m_dataResolution[0]*m_dataResolution[1]*m_dataResolution[2]; if ( datasize == 0 ) return; uint8_t* data; bool smooth = false; - if ( convolutionSize != 0 ) + if ( m_convolutionSize != 0 ) { data = new uint8_t[datasize]; memcpy(data, _data, datasize*sizeof(uint8_t)); @@ -786,9 +786,9 @@ namespace sofa::helper data = _data; } - type::Vec3i bboxMin = type::Vec3i ( bbox.min / cubeStep ); - type::Vec3i bboxMax = type::Vec3i ( bbox.max / cubeStep ); - type::Vec3i gridSize = type::Vec3i ( dataResolution /cubeStep ); + type::Vec3i bboxMin = type::Vec3i ( m_bbox.min / m_cubeStep ); + type::Vec3i bboxMax = type::Vec3i ( m_bbox.max / m_cubeStep ); + type::Vec3i gridSize = type::Vec3i ( m_dataResolution /m_cubeStep ); int index; for ( int k=bboxMin[2]; k& mCubeCoords, const vector& realCoords ) const { mCubeCoords.clear(); - const type::Vec3 gridSize ( 1_sreal / dataVoxelSize[0]*cubeStep, - 1_sreal / dataVoxelSize[1]*cubeStep, - 1_sreal / dataVoxelSize[2]*cubeStep ); + const type::Vec3 gridSize ( 1_sreal / m_dataVoxelSize[0]*m_cubeStep, + 1_sreal / m_dataVoxelSize[1]*m_cubeStep, + 1_sreal / m_dataVoxelSize[2]*m_cubeStep ); for ( vector::const_iterator it = realCoords.begin(); it != realCoords.end(); ++it ) { - const type::Vec3 seed = ( ( *it ) - verticesTranslation - ( dataVoxelSize/ 2_sreal ) ).linearProduct ( gridSize ); + const type::Vec3 seed = ( ( *it ) - m_verticesTranslation - ( m_dataVoxelSize/ 2_sreal ) ).linearProduct ( gridSize ); const type::Vec3i intSeed {static_cast(seed.x()), static_cast(seed.y()), static_cast(seed.z())}; mCubeCoords.push_back ( intSeed ); assert ( intSeed[0] >= 0 ); @@ -839,12 +839,12 @@ namespace sofa::helper void MarchingCubeUtility::setVerticesIndexOffset( unsigned int verticesIndexOffset) { - this->verticesIndexOffset = verticesIndexOffset; + this->m_verticesIndexOffset = verticesIndexOffset; } void MarchingCubeUtility::setVerticesTranslation( type::Vec3 verticesTranslation) { - this->verticesTranslation = verticesTranslation; + this->m_verticesTranslation = verticesTranslation; } @@ -852,14 +852,14 @@ namespace sofa::helper void MarchingCubeUtility::updateTriangleInRegularGridVector ( type::vector< type::vector >& triangleIndexInRegularGrid, const type::Vec3i& coord, const GridCell& cell, unsigned int nbTriangles ) const { vector voxels; - if ( cell.val[0] ) voxels.push_back ( ( coord[0]+0 ) + ( coord[1]+0 ) *dataResolution[0] + ( coord[2]+0 ) *dataResolution[0]*dataResolution[1] ); //les voxels occupes ds ce cube - if ( cell.val[1] ) voxels.push_back ( ( coord[0]+1 ) + ( coord[1]+0 ) *dataResolution[0] + ( coord[2]+0 ) *dataResolution[0]*dataResolution[1] ); //les voxels occupes ds ce cube - if ( cell.val[3] ) voxels.push_back ( ( coord[0]+0 ) + ( coord[1]+1 ) *dataResolution[0] + ( coord[2]+0 ) *dataResolution[0]*dataResolution[1] ); //les voxels occupes ds ce cube - if ( cell.val[2] ) voxels.push_back ( ( coord[0]+1 ) + ( coord[1]+1 ) *dataResolution[0] + ( coord[2]+0 ) *dataResolution[0]*dataResolution[1] ); //les voxels occupes ds ce cube - if ( cell.val[4] ) voxels.push_back ( ( coord[0]+0 ) + ( coord[1]+0 ) *dataResolution[0] + ( coord[2]+1 ) *dataResolution[0]*dataResolution[1] ); //les voxels occupes ds ce cube - if ( cell.val[5] ) voxels.push_back ( ( coord[0]+1 ) + ( coord[1]+0 ) *dataResolution[0] + ( coord[2]+1 ) *dataResolution[0]*dataResolution[1] ); //les voxels occupes ds ce cube - if ( cell.val[7] ) voxels.push_back ( ( coord[0]+0 ) + ( coord[1]+1 ) *dataResolution[0] + ( coord[2]+1 ) *dataResolution[0]*dataResolution[1] ); //les voxels occupes ds ce cube - if ( cell.val[6] ) voxels.push_back ( ( coord[0]+1 ) + ( coord[1]+1 ) *dataResolution[0] + ( coord[2]+1 ) *dataResolution[0]*dataResolution[1] ); //les voxels occupes ds ce cube + if ( cell.val[0] ) voxels.push_back ( ( coord[0]+0 ) + ( coord[1]+0 ) *m_dataResolution[0] + ( coord[2]+0 ) *m_dataResolution[0]*m_dataResolution[1] ); //les voxels occupes ds ce cube + if ( cell.val[1] ) voxels.push_back ( ( coord[0]+1 ) + ( coord[1]+0 ) *m_dataResolution[0] + ( coord[2]+0 ) *m_dataResolution[0]*m_dataResolution[1] ); //les voxels occupes ds ce cube + if ( cell.val[3] ) voxels.push_back ( ( coord[0]+0 ) + ( coord[1]+1 ) *m_dataResolution[0] + ( coord[2]+0 ) *m_dataResolution[0]*m_dataResolution[1] ); //les voxels occupes ds ce cube + if ( cell.val[2] ) voxels.push_back ( ( coord[0]+1 ) + ( coord[1]+1 ) *m_dataResolution[0] + ( coord[2]+0 ) *m_dataResolution[0]*m_dataResolution[1] ); //les voxels occupes ds ce cube + if ( cell.val[4] ) voxels.push_back ( ( coord[0]+0 ) + ( coord[1]+0 ) *m_dataResolution[0] + ( coord[2]+1 ) *m_dataResolution[0]*m_dataResolution[1] ); //les voxels occupes ds ce cube + if ( cell.val[5] ) voxels.push_back ( ( coord[0]+1 ) + ( coord[1]+0 ) *m_dataResolution[0] + ( coord[2]+1 ) *m_dataResolution[0]*m_dataResolution[1] ); //les voxels occupes ds ce cube + if ( cell.val[7] ) voxels.push_back ( ( coord[0]+0 ) + ( coord[1]+1 ) *m_dataResolution[0] + ( coord[2]+1 ) *m_dataResolution[0]*m_dataResolution[1] ); //les voxels occupes ds ce cube + if ( cell.val[6] ) voxels.push_back ( ( coord[0]+1 ) + ( coord[1]+1 ) *m_dataResolution[0] + ( coord[2]+1 ) *m_dataResolution[0]*m_dataResolution[1] ); //les voxels occupes ds ce cube for ( size_t i = 0; i < nbTriangles; i++ ) { @@ -871,8 +871,8 @@ namespace sofa::helper void MarchingCubeUtility::findConnectedVoxels ( std::set& connectedVoxels, const float isoValue, const type::Vec3i& from, unsigned char* data ) { - type::Vec3i bboxMin = type::Vec3i ( bbox.min / cubeStep ); - type::Vec3i bboxMax = type::Vec3i ( bbox.max / cubeStep ); + type::Vec3i bboxMin = type::Vec3i ( m_bbox.min / m_cubeStep ); + type::Vec3i bboxMax = type::Vec3i ( m_bbox.max / m_cubeStep ); const int minX = bboxMin[0]; const int minY = bboxMin[1]; const int minZ = bboxMin[2]; @@ -888,7 +888,7 @@ namespace sofa::helper type::Vec3i coord = voxelsToTest.top(); voxelsToTest.pop(); - const int index = coord[0] + coord[1]*dataResolution[0] + coord[2]*dataResolution[0]*dataResolution[1]; + const int index = coord[0] + coord[1]*m_dataResolution[0] + coord[2]*m_dataResolution[0]*m_dataResolution[1]; if ( connectedVoxels.contains ( index )) continue; @@ -909,28 +909,28 @@ namespace sofa::helper void MarchingCubeUtility::smoothData ( unsigned char *data ) const { - msg_info() << "Smoothing Data using " << convolutionSize << "x"<< convolutionSize << "x"<< convolutionSize << " as gaussian convolution kernel\n"; + msg_info() << "Smoothing Data using " << m_convolutionSize << "x"<< m_convolutionSize << "x"<< m_convolutionSize << " as gaussian convolution kernel\n"; vector< float > convolutionKernel; createGaussianConvolutionKernel ( convolutionKernel ); - vector input_data ( ( int ) ( ( dataResolution[0]+convolutionSize ) - * ( dataResolution[1]+convolutionSize ) - * ( dataResolution[2]+convolutionSize ) ), + vector input_data ( ( int ) ( ( m_dataResolution[0]+m_convolutionSize ) + * ( m_dataResolution[1]+m_convolutionSize ) + * ( m_dataResolution[2]+m_convolutionSize ) ), 0 ); - for ( int k=0; k &convolutionKernel ) const { - if ( convolutionSize<=1 ) + if ( m_convolutionSize<=1 ) { convolutionKernel.resize ( 1, 1.0f ); return; } else { - convolutionKernel.resize ( convolutionSize*convolutionSize*convolutionSize ); + convolutionKernel.resize ( m_convolutionSize*m_convolutionSize*m_convolutionSize ); } - const float step = 4.0f / ( float ) ( convolutionSize-1 ); + const float step = 4.0f / ( float ) ( m_convolutionSize-1 ); float total = 0.0; size_t idx=0; - for ( unsigned int k=0; kconvolutionSize = convolutionSize; + this->m_convolutionSize = convolutionSize; } /// Set the bounding box from real coords to apply mCube locally. void setBoundingBoxFromRealCoords ( const type::Vec3& min, const type::Vec3& max ) { - type::Vec3 gridSize = dataVoxelSize * cubeStep; + type::Vec3 gridSize = m_dataVoxelSize * m_cubeStep; gridSize = type::Vec3 ( 1_sreal / gridSize[0], 1_sreal / gridSize[1], 1_sreal / gridSize[2] ); // Vec3i bbMin = ( min - verticesTranslation - ( dataVoxelSize/2.0 ) ).linearProduct ( gridSize ); @@ -80,14 +80,14 @@ class SOFA_HELPER_API MarchingCubeUtility /// Set the bounding box (in the data space) to apply mCube locally. void setROI ( const type::Vec3i& min, const type::Vec3i& max ) { - this->roi.min = min; - this->roi.max = max; - if ( roi.min[0] < 0 ) roi.min[0] = 0; - if ( roi.min[1] < 0 ) roi.min[1] = 0; - if ( roi.min[2] < 0 ) roi.min[2] = 0; - if ( roi.max[0] > dataResolution[0] )roi.max[0] = dataResolution[0]; - if ( roi.max[1] > dataResolution[1] )roi.max[1] = dataResolution[1]; - if ( roi.max[2] > dataResolution[2] )roi.max[2] = dataResolution[2]; + this->m_roi.min = min; + this->m_roi.max = max; + if ( m_roi.min[0] < 0 ) m_roi.min[0] = 0; + if ( m_roi.min[1] < 0 ) m_roi.min[1] = 0; + if ( m_roi.min[2] < 0 ) m_roi.min[2] = 0; + if ( m_roi.max[0] > m_dataResolution[0] )m_roi.max[0] = m_dataResolution[0]; + if ( m_roi.max[1] > m_dataResolution[1] )m_roi.max[1] = m_dataResolution[1]; + if ( m_roi.max[2] > m_dataResolution[2] )m_roi.max[2] = m_dataResolution[2]; } /// Set the bounding box (in the data space) to apply mCube locally. @@ -101,14 +101,14 @@ class SOFA_HELPER_API MarchingCubeUtility /// Set the bounding box (in the data space) to apply mCube locally. void setBoundingBox ( const type::Vec3i& min, const type::Vec3i& max ) { - this->bbox.min = min; - this->bbox.max = max; - if ( bbox.min[0] < 0 ) bbox.min[0] = 0; - if ( bbox.min[1] < 0 ) bbox.min[1] = 0; - if ( bbox.min[2] < 0 ) bbox.min[2] = 0; - if ( bbox.max[0] > dataResolution[0] )bbox.max[0] = dataResolution[0]; - if ( bbox.max[1] > dataResolution[1] )bbox.max[1] = dataResolution[1]; - if ( bbox.max[2] > dataResolution[2] )bbox.max[2] = dataResolution[2]; + this->m_bbox.min = min; + this->m_bbox.max = max; + if ( m_bbox.min[0] < 0 ) m_bbox.min[0] = 0; + if ( m_bbox.min[1] < 0 ) m_bbox.min[1] = 0; + if ( m_bbox.min[2] < 0 ) m_bbox.min[2] = 0; + if ( m_bbox.max[0] > m_dataResolution[0] )m_bbox.max[0] = m_dataResolution[0]; + if ( m_bbox.max[1] > m_dataResolution[1] )m_bbox.max[1] = m_dataResolution[1]; + if ( m_bbox.max[2] > m_dataResolution[2] )m_bbox.max[2] = m_dataResolution[2]; } /// given a set of data (size of the data and size of the marching cube beeing defined previously), @@ -209,14 +209,14 @@ class SOFA_HELPER_API MarchingCubeUtility type::vector< type::vector >* triangleIndexInRegularGrid = nullptr, bool propagate = true ) const; - unsigned int cubeStep; - unsigned int convolutionSize; - type::Vec3i dataResolution; - type::Vec3 dataVoxelSize; - BoundingBox bbox; //bbox used to remesh - BoundingBox roi; // Set value to 0 on this limit to always obtain manifold mesh. (Set to d_dataResolution by default but can be changed for ROI) - unsigned int verticesIndexOffset; - type::Vec3 verticesTranslation; + unsigned int m_cubeStep; + unsigned int m_convolutionSize; + type::Vec3i m_dataResolution; + type::Vec3 m_dataVoxelSize; + BoundingBox m_bbox; //bbox used to remesh + BoundingBox m_roi; // Set value to 0 on this limit to always obtain manifold mesh. (Set to d_dataResolution by default but can be changed for ROI) + unsigned int m_verticesIndexOffset; + type::Vec3 m_verticesTranslation; }; extern SOFA_HELPER_API const int MarchingCubeEdgeTable[256]; diff --git a/Sofa/framework/Helper/src/sofa/helper/OptionsGroup.cpp b/Sofa/framework/Helper/src/sofa/helper/OptionsGroup.cpp index d282badc11d..3118c2240ce 100644 --- a/Sofa/framework/Helper/src/sofa/helper/OptionsGroup.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/OptionsGroup.cpp @@ -63,9 +63,12 @@ void OptionsGroup::setItemName(const unsigned int id_item, const std::string& na /////////////////////////////////////// int OptionsGroup::isInOptionsList(const std::string & tempostring) const { - for(std::size_t i=0; i(i); + } } return -1; } diff --git a/Sofa/framework/Helper/src/sofa/helper/RandomGenerator.cpp b/Sofa/framework/Helper/src/sofa/helper/RandomGenerator.cpp index e0771223651..e651bee9aa4 100644 --- a/Sofa/framework/Helper/src/sofa/helper/RandomGenerator.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/RandomGenerator.cpp @@ -54,7 +54,7 @@ RandomGenerator::RandomGenerator() } RandomGenerator::RandomGenerator(long seed) - : seed(seed) + : m_seed(seed) { initSeed(seed); } @@ -65,7 +65,7 @@ RandomGenerator::~RandomGenerator() void RandomGenerator::initSeed(long seed) { - this->seed = seed; + this->m_seed = seed; __rand48_seed[0] = RAND48_SEED_0; __rand48_seed[1] = (unsigned short) seed; diff --git a/Sofa/framework/Helper/src/sofa/helper/RandomGenerator.h b/Sofa/framework/Helper/src/sofa/helper/RandomGenerator.h index 92a17aee50c..5cd477980ea 100644 --- a/Sofa/framework/Helper/src/sofa/helper/RandomGenerator.h +++ b/Sofa/framework/Helper/src/sofa/helper/RandomGenerator.h @@ -47,12 +47,12 @@ class SOFA_HELPER_API RandomGenerator unsigned short __rand48_mult[3]; unsigned short __rand48_add; - long seed; - void __dorand48(unsigned short xseed[3]); protected: + long m_seed {}; + /// integer between [0, 2^32-1) unsigned long int randomBase(); diff --git a/Sofa/framework/Helper/src/sofa/helper/TriangleOctree.cpp b/Sofa/framework/Helper/src/sofa/helper/TriangleOctree.cpp index 87b9c7cc294..b97a13c15c3 100644 --- a/Sofa/framework/Helper/src/sofa/helper/TriangleOctree.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/TriangleOctree.cpp @@ -40,23 +40,28 @@ TriangleOctree::~TriangleOctree() void TriangleOctree::draw (sofa::helper::visual::DrawTool* drawTool) { - type::Vec3 center; - if ( objects.size ()) + if (!objects.empty()) { - center = - (type::Vec3 (x, y, z) + type::Vec3 (size / 2, size / 2, size / 2)); + const auto x_f = static_cast(x); + const auto y_f = static_cast(y); + const auto z_f = static_cast(z); + const auto size_f = static_cast(size); + + const type::Vec3f center = type::Vec3f(x_f, y_f, z_f) + type::Vec3f(size_f / 2, size_f / 2, size_f / 2); drawTool->pushMatrix(); - drawTool->translate((float)center[0], (float)center[1], (float)center[2]); + drawTool->translate(center[0], center[1], center[2]); drawTool->setPolygonMode(0, false); - drawTool->drawCube(size, sofa::type::RGBAColor(0.5f, 0.5f, 0.5f, 1.0f)); + drawTool->drawCube(size_f, sofa::type::RGBAColor::gray()); drawTool->popMatrix(); drawTool->setPolygonMode(0, true); } - for (int i = 0; i < 8; i++) + for (auto& childOctree : childVec) { - if (childVec[i]) - childVec[i]->draw(drawTool); + if (childOctree) + { + childOctree->draw(drawTool); + } } } diff --git a/Sofa/framework/Helper/src/sofa/helper/io/Image.cpp b/Sofa/framework/Helper/src/sofa/helper/io/Image.cpp index 084bb72c573..73fa22b2d8f 100644 --- a/Sofa/framework/Helper/src/sofa/helper/io/Image.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/io/Image.cpp @@ -143,7 +143,7 @@ static unsigned tableBytes[Image::COUNT_OF_DATA_TYPES][Image::COUNT_OF_CHANNEL_F }; Image::Image() - : m_bLoaded(0), data(nullptr) + : m_bLoaded(0), m_data(nullptr) { } @@ -153,48 +153,51 @@ Image::~Image() } Image::Image(const Image& rhs) - :data(nullptr) + :m_data(nullptr) { - init(rhs.width,rhs.height,rhs.depth,rhs.mipmaps,rhs.dataType,rhs.channelFormat); - memcpy(data,rhs.data,getImageSize()); + init(rhs.m_width,rhs.m_height,rhs.m_depth,rhs.m_mipmaps,rhs.m_dataType,rhs.m_channelFormat); + memcpy(m_data,rhs.m_data,getImageSize()); m_bLoaded = rhs.m_bLoaded; } Image& Image::operator=(const Image& rhs) { + if (this == &rhs) + return *this; + clear(); - init(rhs.width,rhs.height,rhs.depth,rhs.mipmaps,rhs.dataType,rhs.channelFormat); - memcpy(data,rhs.data,getImageSize()); + init(rhs.m_width,rhs.m_height,rhs.m_depth,rhs.m_mipmaps,rhs.m_dataType,rhs.m_channelFormat); + memcpy(m_data,rhs.m_data,getImageSize()); m_bLoaded = rhs.m_bLoaded; return *this; } unsigned Image::getWidth(unsigned mipmap) const { - const unsigned result = width >> mipmap; + const unsigned result = m_width >> mipmap; return result ? result : 1; } unsigned Image::getHeight(unsigned mipmap) const { - const unsigned result = height >> mipmap; + const unsigned result = m_height >> mipmap; return result ? result : 1; } unsigned Image::getDepth(unsigned mipmap) const { - const unsigned result = depth >> mipmap; + const unsigned result = m_depth >> mipmap; return result ? result : 1; } unsigned Image::getBytesPerPixel() const { - return dataType != UCOMPRESSED ? tableBytes[dataType][channelFormat] : 0; + return m_dataType != UCOMPRESSED ? tableBytes[m_dataType][m_channelFormat] : 0; } unsigned Image::getBytesPerBlock() const { - return dataType == UCOMPRESSED ? tableBytes[UCOMPRESSED][channelFormat] : 0; + return m_dataType == UCOMPRESSED ? tableBytes[UCOMPRESSED][m_channelFormat] : 0; } unsigned Image::getBytesPerChannel() const @@ -216,12 +219,12 @@ unsigned Image::getChannelCount() const 4 // BGRA }; - return table[channelFormat]; + return table[m_channelFormat]; } unsigned Image::getMipmapCount() const { - return mipmaps; + return m_mipmaps; } unsigned Image::getPixelCount() const @@ -242,7 +245,7 @@ unsigned Image::getMipmapSize(unsigned mipmap) const const unsigned height = getHeight(mipmap); const unsigned depth = (getTextureType() == TEXTURE_CUBE)? 6 : getDepth(mipmap); - if (dataType == UCOMPRESSED) + if (m_dataType == UCOMPRESSED) return ((width + 3) >> 2) * ((height + 3) >> 2) * depth * getBytesPerBlock(); return width * height * depth * getBytesPerPixel(); @@ -261,29 +264,29 @@ unsigned Image::getMipmapRangeSize(unsigned firstMipmap, unsigned mipmaps) const unsigned Image::getImageSize() const { - return getMipmapRangeSize(0, mipmaps); + return getMipmapRangeSize(0, m_mipmaps); } Image::DataType Image::getDataType() const { - return dataType; + return m_dataType; } Image::ChannelFormat Image::getChannelFormat() const { - return channelFormat; + return m_channelFormat; } Image::TextureType Image::getTextureType() const { - if (dataType == UCOMPRESSED && channelFormat >= BGR) + if (m_dataType == UCOMPRESSED && m_channelFormat >= BGR) return TEXTURE_INVALID; - if (depth == 0 && width == height) + if (m_depth == 0 && m_width == m_height) return TEXTURE_CUBE; - else if(depth > 1) + else if(m_depth > 1) return TEXTURE_3D; - else if (depth == 1) + else if (m_depth == 1) return TEXTURE_2D; else return TEXTURE_INVALID; @@ -291,21 +294,21 @@ Image::TextureType Image::getTextureType() const unsigned char *Image::getPixels() { - return data; + return m_data; } unsigned char *Image::getMipmapPixels(unsigned mipmap) { if (getTextureType() == TEXTURE_CUBE) return nullptr; - return data + getMipmapRangeSize(0, mipmap); + return m_data + getMipmapRangeSize(0, mipmap); } unsigned char *Image::getCubeMipmapPixels(unsigned cubeside, unsigned mipmap) { if (getTextureType() != TEXTURE_CUBE) return nullptr; - return data + (cubeside * getImageSize() + getMipmapRangeSize(0, mipmap)) / 6; + return m_data + (cubeside * getImageSize() + getMipmapRangeSize(0, mipmap)) / 6; } unsigned char *Image::get3DSliceMipmapPixels(unsigned slice, unsigned mipmap) @@ -317,8 +320,8 @@ unsigned char *Image::get3DSliceMipmapPixels(unsigned slice, unsigned mipmap) void Image::clear() { - if (data) free(data); - data = nullptr; + if (m_data) free(m_data); + m_data = nullptr; m_bLoaded = 0; } @@ -326,18 +329,18 @@ void Image::init(unsigned width, unsigned height, unsigned depth, unsigned mipma DataType dataType, ChannelFormat channelFormat) { clear(); - this->width = width; - this->height = height; - this->depth = depth; - this->mipmaps = mipmaps; - this->dataType = dataType; - this->channelFormat = channelFormat; + this->m_width = width; + this->m_height = height; + this->m_depth = depth; + this->m_mipmaps = mipmaps; + this->m_dataType = dataType; + this->m_channelFormat = channelFormat; #if 0 printf("init: w=%i, h=%i, d=%i, mipmaps=%i, type=%s, channels=%s, textype=%s\n", width, height, depth, mipmaps, strFromDataType[dataType], strFromChannelFormat[channelFormat], strFromTextureType[getTextureType()]); #endif - data = (unsigned char*)malloc(getImageSize()); + m_data = (unsigned char*)malloc(getImageSize()); } void Image::init(unsigned width, unsigned height, unsigned bpp) diff --git a/Sofa/framework/Helper/src/sofa/helper/io/Image.h b/Sofa/framework/Helper/src/sofa/helper/io/Image.h index bd0d852821d..79c013d2b5a 100644 --- a/Sofa/framework/Helper/src/sofa/helper/io/Image.h +++ b/Sofa/framework/Helper/src/sofa/helper/io/Image.h @@ -141,10 +141,10 @@ class SOFA_HELPER_API Image unsigned char m_bLoaded; private: - unsigned width, height, depth, mipmaps; - DataType dataType; - ChannelFormat channelFormat; - unsigned char *data; + unsigned m_width {}, m_height {}, m_depth {}, m_mipmaps {}; + DataType m_dataType; + ChannelFormat m_channelFormat; + unsigned char *m_data { nullptr }; }; } // namespace sofa::helper::io diff --git a/Sofa/framework/Helper/src/sofa/helper/system/FileSystem.cpp b/Sofa/framework/Helper/src/sofa/helper/system/FileSystem.cpp index 47fc613981b..08af716eda9 100644 --- a/Sofa/framework/Helper/src/sofa/helper/system/FileSystem.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/system/FileSystem.cpp @@ -230,7 +230,6 @@ bool FileSystem::removeDirectory(const std::string& path) #ifdef WIN32 if (RemoveDirectory(sofa::helper::widenString(path).c_str()) == 0) { - DWORD errorCode = ::GetLastError(); msg_error("FileSystem::removedirectory()") << path << ": " << Utils::GetLastError(); return true; } @@ -245,7 +244,7 @@ bool FileSystem::removeDirectory(const std::string& path) } -bool FileSystem::exists(const std::string& path, bool quiet) +bool FileSystem::exists(const std::string& path, [[maybe_unused]] bool quiet) { #if defined(WIN32) ::SetLastError(0); @@ -275,7 +274,7 @@ bool FileSystem::exists(const std::string& path, bool quiet) } -bool FileSystem::isDirectory(const std::string& path, bool quiet) +bool FileSystem::isDirectory(const std::string& path, [[maybe_unused]] bool quiet) { #if defined(WIN32) const DWORD fileAttrib = GetFileAttributes(sofa::helper::widenString(path).c_str());