MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / fromUVPoints

Function fromUVPoints

source/mrmeshnumpy/MRPythonNumpyExposing.cpp:110–239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108}
109
110MR::Mesh fromUVPoints( const pybind11::buffer& xArray, const pybind11::buffer& yArray, const pybind11::buffer& zArray )
111{
112 pybind11::buffer_info xInfo = xArray.request();
113 pybind11::buffer_info yInfo = yArray.request();
114 pybind11::buffer_info zInfo = zArray.request();
115
116 MR::Vector2i shape;
117 int format = -1; // 0 - float, 1 - double
118 auto checkArray = [&] ( const pybind11::buffer_info& info, const std::string& arrayName )->bool
119 {
120 if ( info.ndim != 2 )
121 {
122 std::string error = arrayName + " should be 2D";
123 throw std::runtime_error( error.c_str() );
124 }
125 MR::Vector2i thisShape;
126 thisShape.x = int( info.shape[0] );
127 thisShape.y = int( info.shape[1] );
128 if ( shape == MR::Vector2i() )
129 shape = thisShape;
130 else if ( shape != thisShape )
131 {
132 std::string error = "Input arrays shapes should be same";
133 throw std::runtime_error( error.c_str() );
134 }
135 int thisFormat = -1;
136 if ( info.format == pybind11::format_descriptor<float>::format() )
137 thisFormat = 0;
138 else if ( info.format == pybind11::format_descriptor<double>::format() )
139 thisFormat = 1;
140
141 if ( format == -1 )
142 format = thisFormat;
143
144 if ( format == -1 )
145 {
146 std::string error = arrayName + " dtype should be float32 or float64";
147 throw std::runtime_error( error.c_str() );
148 }
149 if ( format != thisFormat )
150 {
151 std::string error = "Arrays should have same dtype";
152 throw std::runtime_error( error.c_str() );
153 }
154 return true;
155 };
156
157 if ( !checkArray( xInfo, "X" ) || !checkArray( yInfo, "Y" ) || !checkArray( zInfo, "Z" ) )
158 return {};
159
160 assert( format != -1 );
161 float* fDataPtr[3];
162 double* dDataPtr[3];
163 std::function<float( int coord, int i )> getter;
164 if ( format == 0 )
165 {
166 fDataPtr[0] = reinterpret_cast< float* >( xInfo.ptr );
167 fDataPtr[1] = reinterpret_cast< float* >( yInfo.ptr );

Callers

nothing calls this directly

Calls 11

ParallelForFunction · 0.85
fromTrianglesFunction · 0.85
push_backMethod · 0.80
requestMethod · 0.45
resizeMethod · 0.45
sizeMethod · 0.45
reserveMethod · 0.45
volumeMethod · 0.45
flipOrientationMethod · 0.45
packMethod · 0.45

Tested by

no test coverage detected