Skip to content

Commit

Permalink
killed all debug outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
ingowald committed Jan 1, 2020
1 parent f0ae4a4 commit c925637
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 28 deletions.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -35,11 +35,19 @@ A few screenshots:
- Ingo Wald
- Fabio Pellacini (University of Rome)
- Stefan Zellman (University of Cologne)
- Will Usher
- Nate Morrical
- lots of other people, through suggestions, bug reports, etc ...


# Release Notes

V 2.3:

- added 'hair' material (can now parse pbrt v3 hair files)
- removed all DLL build for windows; now using only static libraries on windows
(this avoids windows issues with passing std::string etc through dll boundaries)

V 2.2:

- have first area light sources (distant and infinite)
Expand Down
23 changes: 23 additions & 0 deletions pbrtParser/impl/semantic/BinaryFileFormat.cpp
Expand Up @@ -67,6 +67,7 @@ namespace pbrt {
TYPE_METAL_MATERIAL,
TYPE_PLASTIC_MATERIAL,
TYPE_TRANSLUCENT_MATERIAL,
TYPE_HAIR_MATERIAL,

TYPE_TEXTURE=30,
TYPE_IMAGE_TEXTURE,
Expand Down Expand Up @@ -299,6 +300,8 @@ namespace pbrt {
return std::make_shared<FourierMaterial>();
case TYPE_METAL_MATERIAL:
return std::make_shared<MetalMaterial>();
case TYPE_HAIR_MATERIAL:
return std::make_shared<HairMaterial>();
case TYPE_FILM:
return std::make_shared<Film>(vec2i(0));
case TYPE_CAMERA:
Expand Down Expand Up @@ -1379,6 +1382,26 @@ namespace pbrt {
}


/*! serialize out to given binary writer */
int HairMaterial::writeTo(BinaryWriter &binary)
{
Material::writeTo(binary);
binary.write(eumelanin);
binary.write(alpha);
binary.write(beta_m);
return TYPE_HAIR_MATERIAL;
}

/*! serialize _in_ from given binary file reader */
void HairMaterial::readFrom(BinaryReader &binary)
{
Material::readFrom(binary);
binary.read(eumelanin);
binary.read(alpha);
binary.read(beta_m);
}




/*! serialize out to given binary writer */
Expand Down
39 changes: 20 additions & 19 deletions pbrtParser/impl/semantic/Geometry.cpp
Expand Up @@ -136,7 +136,6 @@ namespace pbrt {
{
Curve::SP ours = std::make_shared<Curve>(findOrCreateMaterial(shape->material));
ours->transform = shape->transform.atStart;

// -------------------------------------------------------
// check 'type'
// -------------------------------------------------------
Expand Down Expand Up @@ -294,24 +293,26 @@ namespace pbrt {
if (emittedShapes.find(pbrtShape) != emittedShapes.end())
return emittedShapes[pbrtShape];

emittedShapes[pbrtShape] = emitShape(pbrtShape);
if (emittedShapes[pbrtShape])
emittedShapes[pbrtShape]->reverseOrientation = pbrtShape->attributes->reverseOrientation;
/* now, add area light sources */
if (!pbrtShape->attributes->areaLightSources.empty()) {
std::cout << "Shape has " << pbrtShape->attributes->areaLightSources.size()
<< " area light sources..." << std::endl;
assert(pbrtShape->attributes);
auto &areaLights = pbrtShape->attributes->areaLightSources;
if (!areaLights.empty()) {
if (areaLights.size() > 1)
std::cout << "Warning: Shape has more than one area light!?" << std::endl;
assert(emittedShapes[pbrtShape]);
emittedShapes[pbrtShape]->areaLight = parseAreaLight(areaLights[0]);
Shape::SP newShape = emitShape(pbrtShape);
emittedShapes[pbrtShape] = newShape;
if (pbrtShape->attributes) {
newShape->reverseOrientation
= pbrtShape->attributes->reverseOrientation;
/* now, add area light sources */

if (!pbrtShape->attributes->areaLightSources.empty()) {
std::cout << "Shape has " << pbrtShape->attributes->areaLightSources.size()
<< " area light sources..." << std::endl;
auto &areaLights = pbrtShape->attributes->areaLightSources;
if (!areaLights.empty()) {
if (areaLights.size() > 1)
std::cout << "Warning: Shape has more than one area light!?" << std::endl;
newShape->areaLight = parseAreaLight(areaLights[0]);
}
}
}
return emittedShapes[pbrtShape];

return newShape;
}


Expand All @@ -324,14 +325,15 @@ namespace pbrt {
}

Object::SP ourObject = std::make_shared<Object>();
emittedObjects[pbrtObject] = ourObject;
ourObject->name = pbrtObject->name;

for (auto lightSource : pbrtObject->lightSources) {
LightSource::SP ourLightSource = findOrCreateLightSource(lightSource);
if (ourLightSource)
ourObject->lightSources.push_back(ourLightSource);
}

for (auto shape : pbrtObject->shapes) {
Shape::SP ourShape = findOrCreateShape(shape);
if (ourShape)
Expand All @@ -341,7 +343,6 @@ namespace pbrt {
for (auto instance : pbrtObject->objectInstances)
ourObject->instances.push_back(emitInstance(instance));

emittedObjects[pbrtObject] = ourObject;
return ourObject;
}

Expand Down
23 changes: 23 additions & 0 deletions pbrtParser/impl/semantic/Materials.cpp
Expand Up @@ -23,6 +23,25 @@

namespace pbrt {

Material::SP SemanticParser::createMaterial_hair(pbrt::syntactic::Material::SP in)
{
HairMaterial::SP mat = std::make_shared<HairMaterial>(in->name);
for (auto it : in->param) {
std::string name = it.first;
if (name == "eumelanin") {
mat->eumelanin = in->getParam1f(name);
} else if (name == "alpha") {
mat->alpha = in->getParam1f(name);
} else if (name == "beta_m") {
mat->beta_m = in->getParam1f(name);
} else if (name == "type") {
/* ignore */
} else
throw std::runtime_error("as-yet-unhandled hair-material parameter '"+it.first+"'");
};
return mat;
}

Material::SP SemanticParser::createMaterial_uber(pbrt::syntactic::Material::SP in)
{
UberMaterial::SP mat = std::make_shared<UberMaterial>(in->name);
Expand Down Expand Up @@ -461,6 +480,10 @@ namespace pbrt {
return createMaterial_glass(in);

// ==================================================================
if (type == "hair")
return createMaterial_hair(in);

// ==================================================================
#ifndef NDEBUG
std::cout << "Warning: un-recognizd material type '"+type+"'" << std::endl;
#endif
Expand Down
1 change: 1 addition & 0 deletions pbrtParser/impl/semantic/SemanticParser.h
Expand Up @@ -114,6 +114,7 @@ namespace pbrt {
/*! @{ type-specific extraction routines (ie, we already know the
type, and only have to extract the potential/expected
parameters) */
Material::SP createMaterial_hair(pbrt::syntactic::Material::SP in);
Material::SP createMaterial_uber(pbrt::syntactic::Material::SP in);
Material::SP createMaterial_metal(pbrt::syntactic::Material::SP in);
Material::SP createMaterial_matte(pbrt::syntactic::Material::SP in);
Expand Down
1 change: 1 addition & 0 deletions pbrtParser/impl/semantic/importPBRT.cpp
Expand Up @@ -507,6 +507,7 @@ namespace pbrt {
result = std::make_shared<Scene>();
result->world = findOrEmitObject(pbrtScene->world);

std::cout << "semantic - done with findoremit" << std::endl;
if (!unhandledShapeTypeCounter.empty()) {
std::cerr << "WARNING: scene contained some un-handled shapes!" << std::endl;
for (auto type : unhandledShapeTypeCounter)
Expand Down
41 changes: 33 additions & 8 deletions pbrtParser/impl/syntactic/Scene.h
Expand Up @@ -103,8 +103,8 @@ namespace pbrt {

// NOT copyable!
Attributes() = default;
Attributes(Attributes&) = delete;
Attributes& operator=(Attributes&) = delete;
Attributes(const Attributes&) = delete;
Attributes& operator=(const Attributes&) = delete;

/*! a "Type::SP" shorthand for std::shared_ptr<Type> - makes code
more concise, and easier to read */
Expand All @@ -130,6 +130,24 @@ namespace pbrt {
/*! Freeze the current graphics state so that it won't be affected
by subsequent changes. Returns the frozen graphics state */
static Attributes::SP freeze(Attributes::SP& graphicsState) {
#if 1
// iw - this CLONES the state, else I get stack overflow in
// destructor chain: for pbrt-v3-scenes/straight-hair.pbrt i
// get 1M hair shapes, and the shapes::clear() then triggers
// what looks like an infinite (or at least,
// too-deep-for-the-stack) chain of Attribute::~Attribute
// calls.
Attributes::SP newGraphicsState = std::make_shared<Attributes>();
newGraphicsState->areaLightSources = graphicsState->areaLightSources;
newGraphicsState->mediumInterface = graphicsState->mediumInterface;
newGraphicsState->reverseOrientation = graphicsState->reverseOrientation;
newGraphicsState->parent = graphicsState->parent;
newGraphicsState->prev = graphicsState;
return newGraphicsState;

#else
// iw, 1/1/20 - this is the code szellman adde to avoid
// un-necessary clones
Attributes::SP newGraphicsState = std::make_shared<Attributes>();
newGraphicsState->areaLightSources = graphicsState->areaLightSources;
newGraphicsState->mediumInterface = graphicsState->mediumInterface;
Expand All @@ -141,20 +159,21 @@ namespace pbrt {
graphicsState = newGraphicsState;
return oldGraphicsState;
#endif
}

/*! Insert named material */
void insertNamedMaterial(std::string name, const std::shared_ptr<Material>& material) {
void insertNamedMaterial(std::string name, std::shared_ptr<Material> material) {
namedMaterial[name] = material;
}

/*! Insert named medium */
void insertNamedMedium(std::string name, const std::shared_ptr<Medium>& medium) {
void insertNamedMedium(std::string name, std::shared_ptr<Medium> medium) {
namedMedium[name] = medium;
}

/*! Insert named texture */
void insertNamedTexture(std::string name, const std::shared_ptr<Texture>& texture) {
void insertNamedTexture(std::string name, std::shared_ptr<Texture> texture) {
namedTexture[name] = texture;
}

Expand Down Expand Up @@ -197,7 +216,7 @@ namespace pbrt {

/*! get reference to namedTexture */
decltype(namedTexture)& get(std::shared_ptr<Texture>) { return namedTexture; }

/*! search this scope for the named item, descend into
parent scopes if not found. Also search prior versions */
template <typename Item>
Expand Down Expand Up @@ -632,14 +651,14 @@ namespace pbrt {
typedef std::shared_ptr<Object> SP;

Object(const std::string &name) : name(name) {}

struct PBRT_PARSER_INTERFACE Instance {

/*! allows for writing pbrt::syntactic::Scene::SP, which is somewhat
more concise than std::shared_ptr<pbrt::syntactic::Scene> */
typedef std::shared_ptr<Instance> SP;

Instance(const std::shared_ptr<Object> &object,
Instance(std::shared_ptr<Object> object,
const Transform &xfm)
: object(object), xfm(xfm)
{}
Expand Down Expand Up @@ -680,6 +699,12 @@ namespace pbrt {
Scene()
: world(std::make_shared<Object>("<root>"))
{}
virtual ~Scene()
{
std::cout << "destructor in scene .." << std::endl;
world = nullptr;
std::cout << "deleted world" << std::endl;
}

/*! parse the given file name, return parsed scene */
static std::shared_ptr<Scene> parse(const std::string &fileName, const std::string &basePath = "");
Expand Down
19 changes: 19 additions & 0 deletions pbrtParser/include/pbrtParser/Scene.h
Expand Up @@ -454,6 +454,25 @@ namespace pbrt {
Texture::SP map_bump;
};

struct HairMaterial : public Material
{
typedef std::shared_ptr<HairMaterial> SP;

/*! constructor */
HairMaterial(const std::string &name = "") : Material(name) {}

/*! pretty-printer, for debugging */
virtual std::string toString() const override { return "HairMaterial"; }
/*! serialize out to given binary writer */
virtual int writeTo(BinaryWriter &) override;
/*! serialize _in_ from given binary file reader */
virtual void readFrom(BinaryReader &) override;

float eumelanin { 1.f };
float beta_m { .25f };
float alpha { 2.f };
};

struct TranslucentMaterial : public Material
{
typedef std::shared_ptr<TranslucentMaterial> SP;
Expand Down
2 changes: 1 addition & 1 deletion test-all.sh
Expand Up @@ -174,6 +174,6 @@ for scene in $PBRT_SCENES; do
mkdir -p $OUTPUT_PATH/$dir
base=`basename $scene .pbrt`
./build/pbrt2pbf $PBRT_SCENE_PATH/$scene -o $OUTPUT_PATH/$dir/$base.pbf
./build/pbfInfo $OUTPUT_PATH/$dir/$base.pbf
./build/pbrtInfo $OUTPUT_PATH/$dir/$base.pbf
done

0 comments on commit c925637

Please sign in to comment.