Skip to content

Commit

Permalink
Add command line support
Browse files Browse the repository at this point in the history
  • Loading branch information
GeometryCollective committed Jun 4, 2019
1 parent 6a7895f commit c62af39
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 31 deletions.
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,28 @@ DDG_OPENGL_LIBS = -framework OpenGL -framework GLUT

#######################################################################################################

TARGET = fieldgen
TARGET = fieldviz
CLTARGET = fieldgen
CC = g++
LD = g++
CFLAGS = -g -Wall -Wno-deprecated -Werror -Wno-error=deprecated-declarations -ansi -pedantic $(DDG_INCLUDE_PATH) -I./include -I./src
LFLAGS = -g -Wall -Wno-deprecated -Werror -pedantic $(DDG_LIBRARY_PATH)
LIBS = $(DDG_OPENGL_LIBS) $(DDG_SUITESPARSE_LIBS) $(DDG_BLAS_LIBS)
CLLIBS = $(DDG_SUITESPARSE_LIBS) $(DDG_BLAS_LIBS)

## !! Do not edit below this line -- dependencies can be updated by running ./update ##################

OBJS = obj/Camera.o obj/Complex.o obj/DenseMatrix.o obj/Edge.o obj/Face.o obj/HalfEdge.o obj/Image.o obj/KVecDir.o obj/LinearContext.o obj/Mesh.o obj/MeshIO.o obj/Quaternion.o obj/Real.o obj/SectionIntegrals.o obj/Shader.o obj/SparseMatrix.o obj/Vector.o obj/Vertex.o obj/Viewer.o obj/main.o
CLOBJS = obj/Complex.o obj/DenseMatrix.o obj/Edge.o obj/Face.o obj/HalfEdge.o obj/KVecDir.o obj/LinearContext.o obj/Mesh.o obj/MeshIO.o obj/Quaternion.o obj/Real.o obj/SectionIntegrals.o obj/SparseMatrix.o obj/Vector.o obj/Vertex.o obj/commandline.o

all: $(TARGET)

$(TARGET): $(OBJS)
$(LD) $(LFLAGS) $(OBJS) $(LIBS) -o $(TARGET)

commandline: $(CLOBJS)
$(LD) $(LFLAGS) $(CLOBJS) $(CLLIBS) -o $(CLTARGET)

obj/Camera.o: src/Camera.cpp include/Camera.h include/Quaternion.h include/Vector.h
$(CC) $(CFLAGS) -c src/Camera.cpp -o obj/Camera.o

Expand Down Expand Up @@ -101,9 +107,15 @@ obj/Viewer.o: src/Viewer.cpp include/Viewer.h include/Mesh.h include/HalfEdge.h
obj/main.o: src/main.cpp include/Viewer.h include/Mesh.h include/HalfEdge.h include/Vector.h include/Types.h include/Complex.h include/Quaternion.h include/Vertex.h include/Edge.h include/Face.h include/AliasTable.h include/Camera.h include/Shader.h include/DenseMatrix.h src/DenseMatrix.inl include/DenseMatrix.h include/LinearContext.h include/Quaternion.h include/SparseMatrix.h src/SparseMatrix.inl include/Real.h include/Complex.h include/Utility.h
$(CC) $(CFLAGS) -c src/main.cpp -o obj/main.o

obj/commandline.o: src/main.cpp include/Mesh.h include/HalfEdge.h include/Vector.h include/Types.h include/Complex.h include/Quaternion.h include/Vertex.h include/Edge.h include/Face.h include/Camera.h include/DenseMatrix.h src/DenseMatrix.inl include/DenseMatrix.h include/LinearContext.h include/Quaternion.h include/SparseMatrix.h src/SparseMatrix.inl include/Real.h include/Complex.h include/Utility.h
$(CC) $(CFLAGS) -c src/commandline.cpp -o obj/commandline.o


clean:
rm -f $(OBJS)
rm -f $(CLOBJS)
rm -f $(TARGET)
rm -f $(TARGET).exe
rm -f $(CLTARGET)
rm -f $(CLTARGET).exe

33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ have been set, simply type
```make```

which (barring any compilation/linker errors) should build an executable
called `fieldgen`.
called `fieldviz`.


## Running

Once built, you should be able to run the executable by typing

```./fieldgen data/bunny.obj```
```./fieldviz data/bunny.obj```

(or specifying a path to any mesh file in OBJ format). You should
see a window showing the mesh and some information in the upper-left
Expand Down Expand Up @@ -133,6 +133,35 @@ where `i` is the index of the vertex, and `x` `y` `z` are the three components o

where `i` is the index of the triangle, and `s` is the degree of the singularity. All indices are 1-based rather than 0-based.

## Command Line

A command line version of `fieldgen` is also available, which can be useful when running in batch mode, over a network, or in other situations where OpenGL visualization is not available or appropriate (e.g., bundling `fieldgen` into a plugin).

**To build:** follow the same instructions above, but type

```make commandline```

instead of just `make`. Doing so should produce an executable called `fieldgen` (rather than `fieldviz`).

**To run:** the only mandatory arguments are paths to the input and output meshes (in OBJ format); by default, `fieldgen` will then compute the smoothest unit vector field. To get a full set of options, type

```./fieldgen```

which should print the usage string

```usage: ./fieldgen OBJ_INPUT_PATH OBJ_OUTPUT_PATH```
``` [--degree=n] [--alignToCurvature] [--alignToBoundary] [--s=S] [--t=T]```

The command line options are as follows:

* `degree` — field degree (1=unit vector field, 2=line field, 4=cross field, etc.)
* `alignToCurvature` — align field to principal curvature directions
* `alignToBoundary` — align field to the domain boundary
* `s/S` — controls the smoothness energy; -1=holomorphic, 0=Dirichlet, 1=antiholomorphic
* `t/T` — controls the trade off between smoothness and curvature alignment (if enabled)

Note that enabling boundary alignment will override curvature alignment.

## Source

Much of the source code in this archive is just there to support basic stuff
Expand Down
3 changes: 0 additions & 3 deletions include/Viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ namespace DDG
static void mToggleFixedBoundary( void );
static void mToggleSingularities( void );
static void mToggleHedgehog( void );
static void mToggleNormalized( void );
static void mResetMesh( void );
static void mWriteMesh( void );
static void mExit( void );
Expand All @@ -95,7 +94,6 @@ namespace DDG
menuScreenshot,
menuToggleAlignment,
menuToggleFixedBoundary,
menuToggleNormalized,
menuToggleHedgehog,
menuToggleSingularities
};
Expand Down Expand Up @@ -128,7 +126,6 @@ namespace DDG

// field parameters
static int fieldDegree; // degree k of k-field
static bool normalized; // whether to normalize vectors
static bool align; // toggles alignment with curvature
static bool fixBoundary; // toggles fixed boundary vectors (Dirichlet conditions)
static double t; // amount of alignment
Expand Down
27 changes: 3 additions & 24 deletions src/Viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace DDG
Camera Viewer::camera;
Shader Viewer::shader;
int Viewer::fieldDegree = 1;
bool Viewer::normalized = true;
bool Viewer::align = false;
bool Viewer::fixBoundary = false;
double Viewer::t = 0.;
Expand Down Expand Up @@ -83,7 +82,6 @@ namespace DDG
glutAddMenuEntry( "[u] Smooth Field", menuSmoothField );
glutAddMenuEntry( "[c] Toggle Curvature", menuToggleAlignment );
glutAddMenuEntry( "[b] Toggle Fixed Boundary", menuToggleFixedBoundary );
glutAddMenuEntry( "[n] Toggle Normalization", menuToggleNormalized );
glutAddMenuEntry( "[r] Reset Mesh", menuResetMesh );
glutAddMenuEntry( "[w] Write Mesh", menuWriteMesh );
glutAddMenuEntry( "[\\] Screenshot", menuScreenshot );
Expand Down Expand Up @@ -125,9 +123,6 @@ namespace DDG
case( menuToggleFixedBoundary ):
mToggleFixedBoundary();
break;
case( menuToggleNormalized ):
mToggleNormalized();
break;
case( menuWriteMesh ):
mWriteMesh();
break;
Expand Down Expand Up @@ -176,15 +171,15 @@ namespace DDG

if( align )
{
mesh.SmoothestCurvatureAlignment( fieldDegree, s, t, normalized );
mesh.SmoothestCurvatureAlignment( fieldDegree, s, t, true );
}
else if( fixBoundary )
{
mesh.ComputeSmoothestFixedBoundary( fieldDegree, s, normalized );
mesh.ComputeSmoothestFixedBoundary( fieldDegree, s, true );
}
else
{
mesh.ComputeSmoothest( fieldDegree, s, normalized );
mesh.ComputeSmoothest( fieldDegree, s, true );
}

fieldViz = true;
Expand Down Expand Up @@ -221,11 +216,6 @@ namespace DDG
if( fixBoundary ) align = false;
}

void Viewer :: mToggleNormalized( void )
{
normalized = !normalized;
}

void Viewer :: mSmoothShaded( void )
{
mode = renderShaded;
Expand Down Expand Up @@ -327,9 +317,6 @@ namespace DDG
case '*':
mToggleSingularities();
break;
// case 'n':
// mToggleNormalized();
// break;
case 27:
mExit();
break;
Expand Down Expand Up @@ -772,14 +759,6 @@ namespace DDG
h += hInc;
}

// display field degree
{
stringstream ss;
ss << "normalized: " << (normalized?"true":"false");
drawString( ss.str(), 16, H-h );
h += hInc;
}

// display s
{
stringstream ss;
Expand Down
108 changes: 108 additions & 0 deletions src/commandline.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#include <string>
#include <iostream>
using namespace std;

#include "DenseMatrix.h"
#include "Mesh.h"
using namespace DDG;

// Command line parsing code courtesy Rohan Sawhney!

void printUsage(const std::string& programName)
{
std::cout << "usage: "
<< programName << " "
<< "OBJ_INPUT_PATH "
<< "OBJ_OUTPUT_PATH "
<< "[--degree=n] "
<< "[--alignToCurvature] "
<< "[--alignToBoundary] "
<< "[--s=S] "
<< "[--t=T]"
<< std::endl;
}

bool doesArgExist(const std::string& arg, const std::string& searchStr)
{
return arg.find(searchStr) != std::string::npos;
}

bool parseArg(const std::string& arg, const std::string& searchStr, std::string& value)
{
if (doesArgExist(arg, searchStr)) {
value = arg.substr(arg.find_first_of(searchStr[searchStr.size()-1]) + 1);
return true;
}

return false;
}

void parseArgs(int argc, char *argv[], std::string& inputPath, std::string& outputPath,
int& degree, bool& alignToCurvature, bool& alignToBoundary, double& s, double& t)
{
if (argc < 3) {
// input and/or output path not specified
printUsage(argv[0]);
exit(EXIT_FAILURE);

} else {
// parse arguments
inputPath = argv[1];
outputPath = argv[2];
std::string degreeStr;
std::string sStr, tStr;

for (int i = 3; i < argc; i++) {
if (parseArg(argv[i], "--degree=", degreeStr)) degree = std::stoi(degreeStr);
if (doesArgExist(argv[i], "--alignToCurvature")) alignToCurvature = true;
if (doesArgExist(argv[i], "--alignToBoundary")) alignToBoundary = true;
if (parseArg(argv[i], "--s=", sStr)) s = std::atof(sStr.c_str());
if (parseArg(argv[i], "--t=", tStr)) t = std::atof(tStr.c_str());
}
}

// aligning to boundary takes precedence over aligning to curvature
if (alignToBoundary) {
alignToCurvature = false;
}
}

int main( int argc, char** argv )
{
// parse command line options
std::string inputPath = "";
std::string outputPath = "";
int degree = 1;
bool alignToCurvature = false;
bool alignToBoundary = false;
double s = 0.;
double t = 0.;
parseArgs( argc, argv, inputPath, outputPath, degree, alignToCurvature, alignToBoundary, s, t );

Mesh mesh;

cout << "Reading mesh from " << inputPath << "..." << endl;
mesh.read( inputPath );

cout << "Computing field..." << endl;
mesh.InitKVecDirData();
mesh.clearSingularities();
if( alignToCurvature )
{
mesh.SmoothestCurvatureAlignment( degree, s, t, true );
}
else if( alignToBoundary )
{
mesh.ComputeSmoothestFixedBoundary( degree, s, true );
}
else
{
mesh.ComputeSmoothest( degree, s, true );
}

cout << "Writing solution to " << outputPath << "..." << endl;
mesh.write( outputPath, degree );

return 0;
}

1 change: 0 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using namespace std;

#include "Viewer.h"
#include "DenseMatrix.h"
using namespace DDG;

int main( int argc, char** argv )
Expand Down

0 comments on commit c62af39

Please sign in to comment.