Skip to content

Optimize mesh generation based on marching cubes#1350

Merged
Grantim merged 24 commits intomasterfrom
marching_cubes_optimization_branch
Jun 23, 2023
Merged

Optimize mesh generation based on marching cubes#1350
Grantim merged 24 commits intomasterfrom
marching_cubes_optimization_branch

Conversation

@oitel
Copy link
Contributor

@oitel oitel commented Jun 22, 2023

No description provided.

@oitel oitel requested a review from Fedr June 22, 2023 12:16
{

struct BaseVolumeConversionParams
struct MRMESH_CLASS BaseVolumeConversionParams
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really necessary to export header-only structs?


namespace
{
constexpr float cQuietNan = std::numeric_limits<float>::quiet_NaN();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can do std::bit_cast< int >( right here

#include "MRPch/MRTBB.h"
#include "MRPch/MROpenvdb.h"

#include <boost/mp11/algorithm.hpp>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was required for the compile-time parameters and their checks; it is reworked and removed now.

TriangulationPlan{}
};

// check if this iter is needed for config
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is "iter"?

if ( iterIndex == 0 )
{
auto base = ( config & ( 1 << 0 ) );
if ( base != ( config & ( 1 << cMapNeighborsShift[1] ) ) )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we prepare ( 1 << cMapNeighborsShift[1] ) beforehand to be sure it is not computed in runtime?

inline Vector3f voxelPositionerLinearInline( const Vector3f& pos0, const Vector3f& pos1, float v0, float v1, float iso )
{
auto ratio = std::clamp( std::abs( iso - v0 ) / std::abs( v1 - v0 ), 0.0f, 1.0f );
const auto ratio = std::clamp( std::abs( iso - v0 ) / std::abs( v1 - v0 ), 0.0f, 1.0f );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need abs here?

Comment on lines +614 to +628
OutEdge outEdge;
switch ( dir )
{
case MR::MarchingCubesHelper::NeighborDir::X:
outEdge = OutEdge::PlusX;
break;
case MR::MarchingCubesHelper::NeighborDir::Y:
outEdge = OutEdge::PlusY;
break;
case MR::MarchingCubesHelper::NeighborDir::Z:
outEdge = OutEdge::PlusZ;
break;
default:
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we replace this complex switch with some simple formula like outEdge = (OutEdge)dir?


float valueB = volume.data[base];
float valueD = volume.data[indexer.getExistingNeighbor( base, outEdge ).get()];
if constexpr ( !boost::mp11::mp_contains<Args, OmitNaNCheck>::value )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just make function parameter F && isNan. And if you do not need to check for NaN, call with [](float){};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reworked the check.

@Grantim Grantim merged commit 3dc13a6 into master Jun 23, 2023
@Grantim Grantim deleted the marching_cubes_optimization_branch branch June 23, 2023 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants