| 108 | } |
| 109 | |
| 110 | MR::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 ); |
nothing calls this directly
no test coverage detected