Skip to content

Commit

Permalink
Make tests compile.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Apr 24, 2020
1 parent 539bb83 commit c6f629b
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 4 deletions.
7 changes: 7 additions & 0 deletions io/GltfWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ static StaticPluginInfo const s_info

CREATE_STATIC_STAGE(GltfWriter, s_info)

GltfWriter::GltfWriter()
{}


GltfWriter::~GltfWriter()
{}

std::string GltfWriter::getName() const { return s_info.name; }

void GltfWriter::addArgs(ProgramArgs& args)
Expand Down
6 changes: 2 additions & 4 deletions io/GltfWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ class PDAL_DLL GltfWriter : public Writer
struct ViewData;

public:
GltfWriter()
{}
~GltfWriter()
{}
GltfWriter();
~GltfWriter();
GltfWriter(const GltfWriter&) = delete;
GltfWriter& operator=(const GltfWriter&) = delete;

Expand Down
4 changes: 4 additions & 0 deletions test/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ PDAL_ADD_TEST(pdal_io_gdal_writer_test
INCLUDES
${GDAL_INCLUDE_DIR}
)
PDAL_ADD_TEST(pdal_io_gltf_writer_test
FILES
io/GltfWriterTest.cpp
)
PDAL_ADD_TEST(pdal_io_las_reader_test
FILES
io/LasReaderTest.cpp
Expand Down
180 changes: 180 additions & 0 deletions test/unit/io/GltfWriterTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/******************************************************************************
* Copyright (c) 2020, Emma Krantz <krantzemmaj@gmail.com>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following
* conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided
* with the distribution.
* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the
* names of its contributors may be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
****************************************************************************/

#include <pdal/pdal_test_main.hpp>

#include <io/BufferReader.hpp>
#include <io/GltfWriter.hpp>
#include <pdal/util/FileUtils.hpp>
#include <pdal/util/OStream.hpp>
#include <pdal/StageFactory.hpp>

#include "Support.hpp"

namespace pdal
{


void testWrite(bool writeNormals, bool writeColors, std::string path)
{
PointTable t;

t.layout()->registerDim(Dimension::Id::X);
t.layout()->registerDim(Dimension::Id::Y);
t.layout()->registerDim(Dimension::Id::Z);

if (writeNormals) {
t.layout()->registerDim(Dimension::Id::NormalX);
t.layout()->registerDim(Dimension::Id::NormalY);
t.layout()->registerDim(Dimension::Id::NormalZ);
}

if (writeColors) {
t.layout()->registerDim(Dimension::Id::Red);
t.layout()->registerDim(Dimension::Id::Blue);
t.layout()->registerDim(Dimension::Id::Green);
}

PointViewPtr v(new PointView(t));
v->setField(Dimension::Id::X, 0, 1);
v->setField(Dimension::Id::Y, 0, 1);
v->setField(Dimension::Id::Z, 0, 0);

v->setField(Dimension::Id::X, 1, 2);
v->setField(Dimension::Id::Y, 1, 1);
v->setField(Dimension::Id::Z, 1, 0);

v->setField(Dimension::Id::X, 2, 1);
v->setField(Dimension::Id::Y, 2, 2);
v->setField(Dimension::Id::Z, 2, 0);

v->setField(Dimension::Id::X, 3, 2);
v->setField(Dimension::Id::Y, 3, 2);
v->setField(Dimension::Id::Z, 3, 2);


if (writeNormals)
{
v->setField(Dimension::Id::NormalX, 0, 0);
v->setField(Dimension::Id::NormalY, 0, 1);
v->setField(Dimension::Id::NormalZ, 0, 0);

v->setField(Dimension::Id::NormalX, 1, 0);
v->setField(Dimension::Id::NormalY, 1, 1);
v->setField(Dimension::Id::NormalZ, 1, 0);

v->setField(Dimension::Id::NormalX, 2, 0);
v->setField(Dimension::Id::NormalY, 2, 1);
v->setField(Dimension::Id::NormalZ, 2, 0);

v->setField(Dimension::Id::NormalX, 3, 1);
v->setField(Dimension::Id::NormalY, 3, 0);
v->setField(Dimension::Id::NormalZ, 3, 0);
}

if (writeColors)
{
v->setField(Dimension::Id::Red, 0, 255);
v->setField(Dimension::Id::Blue, 0, 0);
v->setField(Dimension::Id::Green, 0, 0);

v->setField(Dimension::Id::Red, 1, 0);
v->setField(Dimension::Id::Blue, 1, 255);
v->setField(Dimension::Id::Green, 1, 0);

v->setField(Dimension::Id::Red, 2, 0);
v->setField(Dimension::Id::Blue, 2, 0);
v->setField(Dimension::Id::Green, 2, 255);

v->setField(Dimension::Id::Red, 3, 255);
v->setField(Dimension::Id::Blue, 3, 0);
v->setField(Dimension::Id::Green, 3, 0);
}

TriangularMesh* mesh = v->createMesh("foo");
mesh->add(0, 1, 2);
mesh->add(3, 2, 1);

BufferReader r;
r.addView(v);

StageFactory factory;
Stage *writer = factory.createStage("writers.gltf");

Options writerOptions;
writerOptions.add("filename", path);
if (writeColors) {
writerOptions.add("color_vertices", true);
}
writer->setOptions(writerOptions);
writer->setInput(r);
writer->prepare(t);
writer->execute(t);
}


TEST(GltfWriter, Write)
{
std::string path = Support::temppath("out.glb");
testWrite(false, false, path);
ASSERT_EQ(FileUtils::fileSize(path), 5100);
}


/**
TEST(GltfWriter, WriteWithNormals)
{
std::string path = Support::temppath("out_normals.glb");
testWrite(true, false, path);
ASSERT_EQ(FileUtils::fileSize(path), 5148);
}
TEST(GltfWriter, WriteWithColors)
{
std::string path = Support::temppath("out_colors.glb");
testWrite(false, true, path);
ASSERT_EQ(FileUtils::fileSize(path), 5148);
}
TEST(GltfWriter, WriteWithNormalsAndColors)
{
std::string path = Support::temppath("out_normals_colors.glb");
testWrite(true, true, path);
ASSERT_EQ(FileUtils::fileSize(path), 5196);
}
**/

} // namespace pdal

0 comments on commit c6f629b

Please sign in to comment.