Skip to content

Commit

Permalink
additional mods addressing #1 and #2
Browse files Browse the repository at this point in the history
  • Loading branch information
chambbj committed May 14, 2013
1 parent a7c8164 commit 0cc3bb8
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 64 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
build
test/temp
27 changes: 17 additions & 10 deletions include/prc/Writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@
#ifndef INCLUDED_DRIVERS_PRC_WRITER_HPP
#define INCLUDED_DRIVERS_PRC_WRITER_HPP

#include <string>

#include <boost/cstdint.hpp>

#include <hpdf.h>

#include <prc/oPRCFile.hpp>

#include <pdal/Writer.hpp>
#include <pdal/FileUtils.hpp>
#include <pdal/StageFactory.hpp>

#include <boost/cstdint.hpp>
//#include <boost/scoped_ptr.hpp>
//#include <boost/tuple/tuple.hpp>

//#include <vector>
#include <string>


namespace pdal
{
Expand Down Expand Up @@ -89,12 +89,19 @@ class PDAL_DLL Writer : public pdal::Writer
virtual void writeEnd(boost::uint64_t actualNumPointsWritten);

oPRCFile m_prcFile;
//PRCoptions grpopt;

//std::string m_prcFilename;
//std::string m_pdfFilename;
int m_outputFormat;

HPDF_REAL m_coox, m_cooy, m_cooz;

void setCOOx(HPDF_REAL coox) { m_coox = coox; }
void setCOOy(HPDF_REAL cooy) { m_cooy = cooy; }
void setCOOz(HPDF_REAL cooz) { m_cooz = cooz; }

HPDF_REAL getCOOx() { return m_coox; }
HPDF_REAL getCOOy() { return m_cooy; }
HPDF_REAL getCOOz() { return m_cooz; }

private:

Writer& operator=(const Writer&); // not implemented
Expand Down
190 changes: 141 additions & 49 deletions src/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@
MAKE_WRITER_CREATOR(prcWriter, pdal::drivers::prc::Writer)
CREATE_WRITER_PLUGIN(prc, pdal::drivers::prc::Writer)

enum OUTPUT_FORMAT {
OUTPUT_FORMAT_PDF,
OUTPUT_FORMAT_PRC
enum OUTPUT_FORMAT
{
OUTPUT_FORMAT_PDF,
OUTPUT_FORMAT_PRC
};


Expand All @@ -73,15 +74,12 @@ namespace prc

Writer::Writer(Stage& prevStage, const Options& options)
: pdal::Writer(prevStage, options)
//, m_prcFile(getOptions().getValueOrThrow<std::string>("prc_filename"))
, m_prcFile(options.getOption("prc_filename").getValue<std::string>())
//, m_prcFilename()
//, m_pdfFilename()
, m_outputFormat(OUTPUT_FORMAT_PDF)
{
std::cout << "writer\n";
std::cout << options.getOption("prc_filename").getValue<std::string>() << std::endl;

return;
}

Expand All @@ -100,11 +98,6 @@ void Writer::initialize()

std::cout << "succes\n";

//m_prcFilename = getOptions().getValueOrThrow<std::string>("prc_filename");
//m_pdfFilename = getOptions().getValueOrThrow<std::string>("pdf_filename");

//std::cout << m_prcFilename << "\n" << m_pdfFilename << std::endl;

std::string output_format = getOptions().getValueOrDefault<std::string>("output_format", "pdf");

if(boost::iequals(output_format, "pdf"))
Expand All @@ -118,8 +111,6 @@ void Writer::initialize()
throw prc_driver_error("Unrecognized output format");
}

//m_prcFile(m_filename);

return;
}

Expand Down Expand Up @@ -168,11 +159,6 @@ void Writer::writeEnd(boost::uint64_t /*actualNumPointsWritten*/)
if(m_outputFormat == OUTPUT_FORMAT_PDF)
{
std::cout << "detected PDF\n";
// std::string prc_name (m_filename);
// std::string pdf_name ("/Users/bchambers/dev/test.pdf");

//std::cout << m_prcFilename << std::endl;
//std::cout << m_pdfFilename << std::endl;

const double width = 256.0f;
const double height = 256.0f;
Expand All @@ -188,6 +174,12 @@ void Writer::writeEnd(boost::uint64_t /*actualNumPointsWritten*/)
HPDF_Dict view;

pdf = HPDF_New( NULL, NULL );
if (!pdf)
{
printf("error: cannot create PdfDoc object\n");
return;
}
std::cout << HPDF_GetError(pdf) << std::endl;
pdf->pdf_version = HPDF_VER_17;

std::cout << "pdf version " << pdf->pdf_version << std::endl;
Expand All @@ -199,24 +191,56 @@ void Writer::writeEnd(boost::uint64_t /*actualNumPointsWritten*/)
std::string prcFilename = getOptions().getValueOrThrow<std::string>("prc_filename");
std::cout << prcFilename;
u3d = HPDF_LoadU3DFromFile( pdf, prcFilename.c_str() );
if (!u3d)
{
printf("error: cannot load U3D object\n");
return;
}
std::cout << HPDF_GetError(pdf) << std::endl;
std::cout << " loaded\n";

view = HPDF_Create3DView( u3d->mmgr, "DefaultView" );
if (!view)
{
printf("error: cannot create view\n");
return;
}
std::cout << "create view: " << HPDF_GetError(pdf) << std::endl;

std::cout << "default view\n";

HPDF_3DView_SetCamera( view, 0, 0, 0, 0, 0, 1, /*depth*/ 10, 0 );
//HPDF_3DView_SetOrthogonalProjection( view, 1 );
HPDF_REAL coox = getCOOx();
HPDF_REAL cooy = getCOOy();
HPDF_REAL cooz = getCOOz();
std::cout << "set cooz: " << HPDF_GetError(pdf) << std::endl;

coox = cooy = 0.0;

printf("%f %f %f\n", coox, cooy, cooz);

HPDF_3DView_SetCamera( view, coox, cooy, cooz, 0, 0, 1, 4*cooz, 0 );
std::cout << "set camera: " << HPDF_GetError(pdf) << std::endl;
HPDF_3DView_SetPerspectiveProjection( view, 30.0 );
std::cout << "set perspective: " << HPDF_GetError(pdf) << std::endl;
HPDF_3DView_SetBackgroundColor( view, 0, 0, 0 );
std::cout << "set background: " << HPDF_GetError(pdf) << std::endl;
HPDF_3DView_SetLighting( view, "Headlamp" );
std::cout << "set lighting: " << HPDF_GetError(pdf) << std::endl;

std::cout << "view created\n";

HPDF_U3D_Add3DView( u3d, view );
std::cout << "add view: " << HPDF_GetError(pdf) << std::endl;
HPDF_U3D_SetDefault3DView( u3d, "DefaultView" );
std::cout << "set default view: " << HPDF_GetError(pdf) << std::endl;

annot = HPDF_Page_Create3DAnnot( page, rect, u3d );
if (!annot)
{
printf("error: cannot create annotation\n");
return;
}
std::cout << "create annotation: " << HPDF_GetError(pdf) << std::endl;

HPDF_Dict action = (HPDF_Dict) HPDF_Dict_GetItem( annot, "3DA", HPDF_OCLASS_DICT );
HPDF_Dict_AddBoolean( action, "TB", HPDF_TRUE );
Expand All @@ -225,8 +249,10 @@ void Writer::writeEnd(boost::uint64_t /*actualNumPointsWritten*/)

std::string pdfFilename = getOptions().getValueOrThrow<std::string>("pdf_filename");
std::cout << pdfFilename;
HPDF_SaveToFile( pdf, pdfFilename.c_str() );
HPDF_STATUS success = HPDF_SaveToFile( pdf, pdfFilename.c_str() );
std::cout << " saved\n";
std::cout << success << std::endl;
std::cout << HPDF_GetErrorDetail(pdf) << std::endl;

HPDF_Free( pdf );
}
Expand All @@ -240,54 +266,120 @@ boost::uint32_t Writer::writeBuffer(const PointBuffer& data)

boost::uint32_t numPoints = 0;

const pdal::Bounds<double>& bounds = data.getSpatialBounds();

double cx = (bounds.getMaximum(0)-bounds.getMinimum(0))/2+bounds.getMinimum(0);
double cy = (bounds.getMaximum(1)-bounds.getMinimum(1))/2+bounds.getMinimum(1);
double cz = (bounds.getMaximum(2)-bounds.getMinimum(2))/2+bounds.getMinimum(2);

setCOOx(static_cast<HPDF_REAL>((bounds.getMaximum(0)-bounds.getMinimum(0))/2+bounds.getMinimum(0)));
setCOOy(static_cast<HPDF_REAL>((bounds.getMaximum(1)-bounds.getMinimum(1))/2+bounds.getMinimum(1)));
setCOOz(static_cast<HPDF_REAL>((bounds.getMaximum(2)-bounds.getMinimum(2))/2+bounds.getMinimum(2)));

pdal::Schema const& schema = data.getSchema();

pdal::Dimension const& dimX = schema.getDimension("X");
pdal::Dimension const& dimY = schema.getDimension("Y");
pdal::Dimension const& dimZ = schema.getDimension("Z");

double **points;
points = (double**) malloc(data.getNumPoints()*sizeof(double*));
for (boost::uint32_t i = 0; i < data.getNumPoints(); ++i)
{
points[i] = (double*) malloc(3*sizeof(double));
}
boost::optional<pdal::Dimension const&> dimR = schema.getDimensionOptional("Red");
boost::optional<pdal::Dimension const&> dimG = schema.getDimensionOptional("Green");
boost::optional<pdal::Dimension const&> dimB = schema.getDimensionOptional("Blue");

double xd(0.0);
double yd(0.0);
double zd(0.0);
bool bHaveColor(false);
if (dimR && dimG && dimB)
bHaveColor = true;

for(boost::uint32_t i = 0; i < data.getNumPoints(); ++i)
if (bHaveColor)
{
boost::int32_t x = data.getField<boost::int32_t>(dimX, i);
boost::int32_t y = data.getField<boost::int32_t>(dimY, i);
boost::int32_t z = data.getField<boost::int32_t>(dimZ, i);
std::cout << "with rgb\n";

xd = dimX.applyScaling<boost::int32_t>(x) - 1210000;
yd = dimY.applyScaling<boost::int32_t>(y) - 320000;
zd = dimZ.applyScaling<boost::int32_t>(z) - 4000;
double **points;
points = (double**) malloc(sizeof(double*));
{
points[0] = (double*) malloc(3*sizeof(double));
}

if(i % 10000) printf("%f %f %f\n", xd, yd, zd);
double xd(0.0);
double yd(0.0);
double zd(0.0);

points[i][0] = xd;
points[i][1] = yd;
points[i][2] = zd;
for(boost::uint32_t i = 0; i < data.getNumPoints(); ++i)
{
boost::int32_t x = data.getField<boost::int32_t>(dimX, i);
boost::int32_t y = data.getField<boost::int32_t>(dimY, i);
boost::int32_t z = data.getField<boost::int32_t>(dimZ, i);

numPoints++;
}
double r = static_cast<double>(data.getField<boost::uint16_t>(*dimR, i))/255.0;
double g = static_cast<double>(data.getField<boost::uint16_t>(*dimG, i))/255.0;
double b = static_cast<double>(data.getField<boost::uint16_t>(*dimB, i))/255.0;

xd = dimX.applyScaling<boost::int32_t>(x) - cx;
yd = dimY.applyScaling<boost::int32_t>(y) - cy;
zd = dimZ.applyScaling<boost::int32_t>(z) - cz;

m_prcFile.addPoints(numPoints, const_cast<const double**>(points), RGBAColour(1.0,1.0,0.0,1.0),1.0);
// if(i % 10000) printf("%f %f %f %f %f %f\n", xd, yd, zd, r, g, b);

for (boost::uint32_t i = 0; i < data.getNumPoints(); ++i)
points[0][0] = xd;
points[0][1] = yd;
points[0][2] = zd;

m_prcFile.addPoints(1, const_cast<const double**>(points), RGBAColour(r,g,b,1.0), 5.0);

numPoints++;
}

{
free(points[0]);
}
free(points);
}
else
{
free(points[i]);
std::cout << "no rgb\n";

double **points;
points = (double**) malloc(data.getNumPoints()*sizeof(double*));
for (boost::uint32_t i = 0; i < data.getNumPoints(); ++i)
{
points[i] = (double*) malloc(3*sizeof(double));
}

double xd(0.0);
double yd(0.0);
double zd(0.0);

for(boost::uint32_t i = 0; i < data.getNumPoints(); ++i)
{
boost::int32_t x = data.getField<boost::int32_t>(dimX, i);
boost::int32_t y = data.getField<boost::int32_t>(dimY, i);
boost::int32_t z = data.getField<boost::int32_t>(dimZ, i);

xd = dimX.applyScaling<boost::int32_t>(x) - cx;
yd = dimY.applyScaling<boost::int32_t>(y) - cy;
zd = dimZ.applyScaling<boost::int32_t>(z) - cz;

// if(i % 10000) printf("%f %f %f\n", xd, yd, zd);

points[i][0] = xd;
points[i][1] = yd;
points[i][2] = zd;

numPoints++;
}

m_prcFile.addPoints(numPoints, const_cast<const double**>(points), RGBAColour(1.0,1.0,0.0,1.0),1.0);

for (boost::uint32_t i = 0; i < data.getNumPoints(); ++i)
{
free(points[i]);
}
free(points);
}
free(points);

return numPoints;
}


}
}
} // namespaces
12 changes: 7 additions & 5 deletions test/pipeline_prc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
<Pipeline version="1.0">
<Writer type="drivers.prc.writer">
<Option name="pdf_filename">
/Users/bchambers/data/autzen.pdf
<!--/Users/bchambers/data/autzen-thin.pdf-->
/Users/bchambers/data/MtStHelens.pdf
</Option>
<Option name="prc_filename">
/Users/bchambers/data/autzen.prc
<!--/Users/bchambers/data/autzen-thin.prc-->
/Users/bchambers/data/MtStHelens.prc
</Option>
<Option name="output_format">
pdf
</Option>
</Option>
<Reader type="drivers.las.reader">
<Option name="filename">
<!-- /Users/bchambers/dev/PRC/test/data/autzen.las-->
/Users/bchambers/data/libLAS_sample_data/MtStHelens.laz
<!--/Users/bchambers/dev/PRC/test/data/autzen-thin.las-->
/Users/bchambers/data/libLAS_sample_data/MtStHelens.laz
</Option>
</Reader>
</Writer>
Expand Down

0 comments on commit 0cc3bb8

Please sign in to comment.