bool MyExportCommand::write_file(std::ofstream& output_file, MeshExportInterface *iface) { // Initialize the exporter iface->initialize_export(); // Fetch and output the coordinates int number_nodes = iface->get_num_nodes(); if(!number_nodes) { CubitMessageHandler* console = CubitInterface::get_cubit_message_handler(); console->print_message("WARNING: No nodes in model...\n"); return false; } output_file << "Test Output for MeshExportInterface\n"; output_file << "Number of Nodes: " << number_nodes << "\n"; output_file << "List of Nodes:\n"; int buf_size = 100; std::vector<double> xcoords(buf_size), ycoords(buf_size), zcoords(buf_size); std::vector<int> node_ids(buf_size); int start = 0, number_found = 0; while ((number_found = iface->get_coords(start, buf_size, xcoords, ycoords, zcoords, node_ids))) { // Write out the coordinates for(int i = 0; i < number_found; i++) { output_file << node_ids[i] << " " << xcoords[i] << " " << ycoords[i] << " " << zcoords[i] << "\n"; } start += number_found; } // Write the connectivity bool result = write_connectivity(output_file, iface); return result; }
void Grid1D<T>::WriteSolution(std::string file) { /* Write VTK Structured Grid file to show the solution. Each scalar and vector quantity will be included in the file. */ std::fstream ssfile; ssfile.open(file.c_str(),std::ios::out); ssfile << "# vtk DataFile Version 2.0" << std::endl; ssfile << gridname << std::endl; ssfile << "ASCII" << std::endl; ssfile << "DATASET STRUCTURED_GRID" << std::endl; ssfile << "DIMENSIONS " << nx << " 1 1" << std::endl; ssfile << "POINTS " << nx << " float" << std::endl; for(int j=0; j<nx; j++){ ssfile << xcoords(i,j) << " " << ycoords(i,j) << " 0.0" << std::endl; } ssfile << "POINT_DATA " << nx << std::endl; for(int s=0; s<nscalars; s++){ std::string name(scalar_names(s)->substr()); ssfile << "SCALARS " << name << " float 1" << std::endl; ssfile << "LOOKUP_TABLE default" << std::endl; for(int j=0; j<nx; j++){ ssfile << pscalars(s)->operator ()(i) << std::endl; } } for(int v=0; v<nvectors; v++){ std::string name(vector_names(v)->substr()); ssfile << "VECTORS " << name << " float" << std::endl; for(int j=0; j<nx; j++){ ssfile << pvectors(v)->operator ()(i,0) << " " << pvectors(v)->operator ()(i,1) << " " << pvectors(v)->operator ()(i,2) << std::endl; } } ssfile.close(); }
ContourConrec::Result ContourConrec::compute( NdArray::RawViewInterface * view ) { // if no input view was set, we are done if ( ! view || m_levels.size() == 0 ) { Result result( m_levels.size() ); return result; } // the c-algorithm conrec() needs the levels in sorted order (to make things little // bit faster), but we would like to report the results in the same order that the // levels were requested. So we need to sort the levels, call the conrec(), and // then we need to 'unsort' the results... typedef std::pair < double, size_t > DI; std::vector < DI > tmpLevels( m_levels.size() ); for ( size_t i = 0 ; i < m_levels.size() ; ++i ) { tmpLevels[i].first = m_levels[i]; tmpLevels[i].second = i; } auto sort1 = [] ( const DI & a, const DI & b ) { return a.first < b.first; }; std::sort( tmpLevels.begin(), tmpLevels.end(), sort1 ); std::vector < double > sortedRawLevels( m_levels.size() ); for ( size_t i = 0 ; i < m_levels.size() ; ++i ) { sortedRawLevels[i] = tmpLevels[i].first; } auto m_nRows = view-> dims()[1]; auto m_nCols = view-> dims()[0]; // make x coordinates VD xcoords( m_nCols ); for ( int col = 0 ; col < m_nCols ; ++col ) { xcoords[col] = col; } // make y coordinates VD ycoords( m_nRows ); for ( int row = 0 ; row < m_nRows ; ++row ) { ycoords[row] = row; } Result result1 = conrecFaster( view, 0, m_nCols - 1, 0, m_nRows - 1, xcoords, ycoords, m_levels.size(), & sortedRawLevels[0] ); Result result; QRectF rect( 0, 0, m_nCols, m_nRows); for( size_t i = 0 ; i < m_levels.size() ; ++ i ) { Carta::Lib::Algorithms::LineCombiner lc( rect, m_nRows+1, m_nCols + 1, 1e-9); std::vector < QPolygonF > & v = result1[i]; for( QPolygonF & poly : v) { for( int i = 0 ; i < poly.size() - 1 ; ++ i ) { lc.add( poly[i], poly[i+1]); } } result.push_back( lc.getPolygons()); qDebug() << "compress" << v.size() << "-->" << result.back().size(); } // Result result = // conrecFaster( // view, // 0, // m_nCols - 1, // 0, // m_nRows - 1, // xcoords, // ycoords, // m_levels.size(), // & sortedRawLevels[0] ); // now we 'unsort' the contours based on the requested order Result unsortedResult( m_levels.size() ); for ( size_t i = 0 ; i < m_levels.size() ; ++i ) { unsortedResult[tmpLevels[i].second] = result[i]; } return unsortedResult; } // compute