Merge pull request #1167 from barfowl/args_regression_common

Moved common command line parsing to regression/common
This commit is contained in:
David G Yu 2019-12-16 23:38:19 -08:00 committed by GitHub
commit 66cd1bd1ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 58 additions and 47 deletions

View File

@ -29,7 +29,6 @@ set(EXAMPLES_COMMON_SHADER_FILES
)
set(EXAMPLES_COMMON_SOURCE_FILES
argOptions.cpp
font_image.cpp
hdr_reader.cpp
hud.cpp
@ -39,7 +38,6 @@ set(EXAMPLES_COMMON_SOURCE_FILES
)
set(EXAMPLES_COMMON_HEADER_FILES
argOptions.h
font_image.h
hdr_reader.h
hud.h

View File

@ -24,10 +24,11 @@
#include "../common/viewerArgsUtils.h"
#include "../../regression/common/arg_utils.h"
#include "../../regression/common/shape_utils.h"
#include "../common/objAnim.h"
#include <fstream>
#include <sstream>
#include <stdio.h>
namespace ViewerArgsUtils {
@ -54,28 +55,9 @@ void
PopulateShapes(const ArgOptions &args,
std::vector<ShapeDesc> *defaultShapes)
{
if (!defaultShapes)
return;
if (args.GetObjFiles().empty())
return;
for (size_t i = 0; i < args.GetObjFiles().size(); ++i) {
std::ifstream ifs(args.GetObjFiles()[i]);
if (ifs) {
std::stringstream ss;
ss << ifs.rdbuf();
ifs.close();
std::string str = ss.str();
defaultShapes->push_back(ShapeDesc(
args.GetObjFiles()[i], str.c_str(),
args.GetDefaultScheme()));
} else {
printf("Warning: cannot open shape file '%s'\n",
args.GetObjFiles()[i]);
}
if (defaultShapes) {
args.AppendObjShapes(*defaultShapes, true /* print warnings */);
}
}
void

View File

@ -25,14 +25,12 @@
#ifndef VIEWER_ARGS_UTILS_H
#define VIEWER_ARGS_UTILS_H
#include "../../regression/common/shape_utils.h"
#include "../common/argOptions.h"
class ObjAnim;
#include <vector>
class ArgOptions;
struct ShapeDesc;
class ObjAnim;
namespace ViewerArgsUtils {
// From the list of obj files in args, populates the

View File

@ -62,7 +62,7 @@ OpenSubdiv::Osd::D3D11LegacyGregoryPatchTable *g_legacyGregoryPatchTable = NULL;
bool g_legacyGregoryEnabled = false;
#include "../../regression/common/far_utils.h"
#include "../common/argOptions.h"
#include "../../regression/common/arg_utils.h"
#include "../common/stopwatch.h"
#include "../common/simple_math.h"
#include "../common/d3d11ControlMeshDisplay.h"

View File

@ -80,7 +80,7 @@ GLFWmonitor* g_primary=0;
#include <opensubdiv/far/error.h>
#include "../../regression/common/far_utils.h"
#include "../common/argOptions.h"
#include "../../regression/common/arg_utils.h"
#include "../common/viewerArgsUtils.h"
#include "../common/stopwatch.h"
#include "../common/simple_math.h"

View File

@ -36,7 +36,7 @@ GLFWmonitor* g_primary = 0;
OpenSubdiv::Osd::GLMeshInterface *g_mesh = NULL;
#include "../../regression/common/far_utils.h"
#include "../common/argOptions.h"
#include "../../regression/common/arg_utils.h"
#include "../common/stopwatch.h"
#include "../common/simple_math.h"
#include "../common/glControlMeshDisplay.h"

View File

@ -69,7 +69,7 @@
#include <opensubdiv/osd/glMesh.h>
#include "../../regression/common/far_utils.h"
#include "../common/argOptions.h"
#include "../../regression/common/arg_utils.h"
#include "../common/patchColors.h"
#include "../common/stb_image_write.h" // common.obj has an implementation.
#include "../common/glShaderCache.h"

View File

@ -37,7 +37,7 @@ GLFWmonitor* g_primary=0;
OpenSubdiv::Osd::GLMeshInterface *g_mesh;
#include "../../regression/common/far_utils.h"
#include "../common/argOptions.h"
#include "../../regression/common/arg_utils.h"
#include "../common/viewerArgsUtils.h"
#include "../common/stopwatch.h"
#include "../common/simple_math.h"

View File

@ -93,7 +93,7 @@ OpenSubdiv::Osd::GLMeshInterface *g_mesh;
#include "PtexUtils.h"
#include "../../regression/common/far_utils.h"
#include "../common/argOptions.h"
#include "../../regression/common/arg_utils.h"
#include "../common/objAnim.h"
#include "../common/stopwatch.h"
#include "../common/simple_math.h"

View File

@ -71,7 +71,7 @@ GLFWmonitor* g_primary=0;
#include "../../regression/common/far_utils.h"
#include "init_shapes.h"
#include "../common/argOptions.h"
#include "../../regression/common/arg_utils.h"
#include "../common/stopwatch.h"
#include "../common/simple_math.h"
#include "../common/glHud.h"

View File

@ -29,7 +29,7 @@ GLFWwindow* g_window=0;
GLFWmonitor* g_primary=0;
#include "../../regression/common/far_utils.h"
#include "../common/argOptions.h"
#include "../../regression/common/arg_utils.h"
#include "../common/viewerArgsUtils.h"
#include "../common/stopwatch.h"
#include "../common/simple_math.h"

View File

@ -74,7 +74,7 @@ OpenSubdiv::Osd::GLLegacyGregoryPatchTable *g_legacyGregoryPatchTable = NULL;
bool g_legacyGregoryEnabled = false;
#include "../../regression/common/far_utils.h"
#include "../common/argOptions.h"
#include "../../regression/common/arg_utils.h"
#include "../common/glHud.h"
#include "../common/glUtils.h"
#include "../common/glControlMeshDisplay.h"

View File

@ -24,7 +24,7 @@
#import <opensubdiv/osd/mtlPatchShaderSource.h>
#import "../../regression/common/far_utils.h"
#import "../common/argOptions.h"
#import "../../regression/common/arg_utils.h"
#import "../common/mtlUtils.h"
#import "../common/mtlControlMeshDisplay.h"
#import "../common/mtlPtexMipmapTexture.h"

View File

@ -48,7 +48,7 @@
#import <opensubdiv/osd/mtlPatchShaderSource.h>
#import "../../regression/common/far_utils.h"
#import "../common/argOptions.h"
#import "../../regression/common/arg_utils.h"
#import "../common/mtlUtils.h"
#import "../common/mtlControlMeshDisplay.h"
#import "../common/simple_math.h"

View File

@ -23,10 +23,12 @@
#
set(REGRESSION_COMMON_SOURCE_FILES
arg_utils.cpp
shape_utils.cpp
)
set(REGRESSION_COMMON_HEADER_FILES
arg_utils.h
cmp_utils.h
hbr_utils.h
shape_utils.h

View File

@ -22,8 +22,10 @@
// language governing permissions and limitations under the Apache License.
//
#include "../common/argOptions.h"
#include "arg_utils.h"
#include <fstream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -99,3 +101,26 @@ ArgOptions::PrintUnrecognizedArgsWarnings() const
PrintUnrecognizedArgWarning(_remainingArgs[i]);
}
}
int
ArgOptions::AppendObjShapes(std::vector<ShapeDesc>& shapes, bool warn) const
{
size_t originalShapesSize = shapes.size();
for (size_t i = 0; i < GetObjFiles().size(); ++i) {
std::ifstream ifs(GetObjFiles()[i]);
if (ifs) {
std::stringstream ss;
ss << ifs.rdbuf();
ifs.close();
std::string str = ss.str();
shapes.push_back(ShapeDesc(
GetObjFiles()[i], str.c_str(),
GetDefaultScheme()));
} else if (warn) {
printf("Warning: cannot open shape file '%s'\n",
GetObjFiles()[i]);
}
}
return shapes.size() - originalShapesSize;
}

View File

@ -22,10 +22,10 @@
// language governing permissions and limitations under the Apache License.
//
#ifndef COMMON_ARGS_H
#define COMMON_ARGS_H
#ifndef ARG_UTILS_H
#define ARG_UTILS_H
#include "../../regression/common/shape_utils.h"
#include "shape_utils.h"
#include <vector>
@ -67,7 +67,13 @@ public:
const std::vector<const char *> GetRemainingArgs() const {
return _remainingArgs; }
// Operations on parsed arguments
//
int AppendObjShapes(std::vector<ShapeDesc>& shapes, bool warn = true) const;
private:
bool _adaptive;