add lab3
This commit is contained in:
76
lab3/grid2off.cpp
Normal file
76
lab3/grid2off.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
// Convert 2D grid of points to Geomview .off file of quadrilaterals.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "grid2DPoints3D.h"
|
||||
#include "grid2DIO.h"
|
||||
#include "writeGrid2DOFF.h"
|
||||
|
||||
|
||||
// ********************* Functions ************************************
|
||||
|
||||
/// Replace the file extension of infilename with ".off".
|
||||
std::string CreateOutFilename(const std::string& infilename) {
|
||||
size_t dot_pos = infilename.rfind('.');
|
||||
std::string basename;
|
||||
if (dot_pos != std::string::npos) {
|
||||
basename = infilename.substr(0, dot_pos);
|
||||
}
|
||||
else {
|
||||
basename = infilename;
|
||||
}
|
||||
return basename + ".off";
|
||||
}
|
||||
|
||||
|
||||
void UsageMsg(const std::string& command_name) {
|
||||
std::cerr << "Usage: " << command_name
|
||||
<< " {input filename} [{output filename}]\n";
|
||||
}
|
||||
|
||||
|
||||
// ********************* Main *****************************************
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
if (argc == 1) {
|
||||
UsageMsg(argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string infilename = argv[1];
|
||||
GRID2D_POINTS3D grid2D;
|
||||
|
||||
try {
|
||||
OpenReadGrid2DPoints3D(infilename, grid2D);
|
||||
}
|
||||
catch (const std::exception&) {
|
||||
std::cerr << "Exiting...\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::string outfilename;
|
||||
if (argc < 3) {
|
||||
outfilename = CreateOutFilename(infilename);
|
||||
}
|
||||
else {
|
||||
outfilename = argv[2];
|
||||
}
|
||||
|
||||
WRITE_GRID2D_OFF writeOFF;
|
||||
std::vector<std::string> comments_list =
|
||||
{"File created from 2D grid of points."};
|
||||
|
||||
try {
|
||||
std::cout << "Writing file " << outfilename << ".\n";
|
||||
writeOFF.OpenAndWrite(outfilename, grid2D, comments_list);
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << e.what() << "\n";
|
||||
std::cerr << "Exiting...\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user