diff --git a/.gitignore b/.gitignore index 378eac2..246a80f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ build +test/temp diff --git a/include/prc/Writer.hpp b/include/prc/Writer.hpp index 061c01a..e81527f 100644 --- a/include/prc/Writer.hpp +++ b/include/prc/Writer.hpp @@ -35,18 +35,18 @@ #ifndef INCLUDED_DRIVERS_PRC_WRITER_HPP #define INCLUDED_DRIVERS_PRC_WRITER_HPP +#include + +#include + +#include + #include + #include #include #include -#include -//#include -//#include - -//#include -#include - namespace pdal { @@ -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 diff --git a/src/Writer.cpp b/src/Writer.cpp index ba32308..b50461a 100644 --- a/src/Writer.cpp +++ b/src/Writer.cpp @@ -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 }; @@ -73,15 +74,12 @@ namespace prc Writer::Writer(Stage& prevStage, const Options& options) : pdal::Writer(prevStage, options) - //, m_prcFile(getOptions().getValueOrThrow("prc_filename")) , m_prcFile(options.getOption("prc_filename").getValue()) - //, m_prcFilename() - //, m_pdfFilename() , m_outputFormat(OUTPUT_FORMAT_PDF) { std::cout << "writer\n"; std::cout << options.getOption("prc_filename").getValue() << std::endl; - + return; } @@ -100,11 +98,6 @@ void Writer::initialize() std::cout << "succes\n"; - //m_prcFilename = getOptions().getValueOrThrow("prc_filename"); - //m_pdfFilename = getOptions().getValueOrThrow("pdf_filename"); - - //std::cout << m_prcFilename << "\n" << m_pdfFilename << std::endl; - std::string output_format = getOptions().getValueOrDefault("output_format", "pdf"); if(boost::iequals(output_format, "pdf")) @@ -118,8 +111,6 @@ void Writer::initialize() throw prc_driver_error("Unrecognized output format"); } - //m_prcFile(m_filename); - return; } @@ -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; @@ -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; @@ -199,24 +191,56 @@ void Writer::writeEnd(boost::uint64_t /*actualNumPointsWritten*/) std::string prcFilename = getOptions().getValueOrThrow("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 ); @@ -225,8 +249,10 @@ void Writer::writeEnd(boost::uint64_t /*actualNumPointsWritten*/) std::string pdfFilename = getOptions().getValueOrThrow("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 ); } @@ -240,54 +266,120 @@ boost::uint32_t Writer::writeBuffer(const PointBuffer& data) boost::uint32_t numPoints = 0; + const pdal::Bounds& 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((bounds.getMaximum(0)-bounds.getMinimum(0))/2+bounds.getMinimum(0))); + setCOOy(static_cast((bounds.getMaximum(1)-bounds.getMinimum(1))/2+bounds.getMinimum(1))); + setCOOz(static_cast((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 dimR = schema.getDimensionOptional("Red"); + boost::optional dimG = schema.getDimensionOptional("Green"); + boost::optional 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(dimX, i); - boost::int32_t y = data.getField(dimY, i); - boost::int32_t z = data.getField(dimZ, i); + std::cout << "with rgb\n"; - xd = dimX.applyScaling(x) - 1210000; - yd = dimY.applyScaling(y) - 320000; - zd = dimZ.applyScaling(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(dimX, i); + boost::int32_t y = data.getField(dimY, i); + boost::int32_t z = data.getField(dimZ, i); - numPoints++; - } + double r = static_cast(data.getField(*dimR, i))/255.0; + double g = static_cast(data.getField(*dimG, i))/255.0; + double b = static_cast(data.getField(*dimB, i))/255.0; + + xd = dimX.applyScaling(x) - cx; + yd = dimY.applyScaling(y) - cy; + zd = dimZ.applyScaling(z) - cz; - m_prcFile.addPoints(numPoints, const_cast(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(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(dimX, i); + boost::int32_t y = data.getField(dimY, i); + boost::int32_t z = data.getField(dimZ, i); + + xd = dimX.applyScaling(x) - cx; + yd = dimY.applyScaling(y) - cy; + zd = dimZ.applyScaling(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(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 diff --git a/test/pipeline_prc.xml b/test/pipeline_prc.xml index a5a28e1..7f2c6a8 100644 --- a/test/pipeline_prc.xml +++ b/test/pipeline_prc.xml @@ -2,18 +2,20 @@ +