How to: Sample code using HOOPS 's OOC Preprocessor (programmatic approach)

Below is a sample code snippet demonstrating how to use OOC::Preprocessor to create an .OOC file.

Note: The data needs to be processed in two passes:

  1. First Pass: Read your data to determine the minimum and maximum values of your points. These values are required to call OOC::Processor::SetCullingBoundingBox(min, max).
  2. Second Pass: Add your points and create the .OOC file.

PointCloud.txt

231.184304018609;28.0413952188606;-52.9060268489888
230.519663194219;27.8575831696436;-53.1020735257726
180.846926122318;14.4033549613675;-65.8973115452756
180.645231895336;14.346701878569;-65.9614782676344
169.487355959823;11.1314395604915;-70.0178583075153
167.585456214966;10.5698552222266;-70.7934752619902
158.059809849517;7.78309520406801;-74.5002518418382
137.452405113955;1.9655581066296;-81.1235261654424
137.239202967066;1.91407596863235;-81.1359134738528
137.007460149156;1.86437470324587;-81.1090716382481

Sample Code:

#include <fstream>
#include <sstream>
#include <climits>

using namespace ooc;
using namespace ooc::preprocess;

static std::string& strip(std::string& s)
{
	s.erase(std::remove(s.begin(), s.end(), ','), s.end());
	return s;
}


void CSolidHoopsView::OnExtraSlot5() {
    std::string str_buf;
    std::string str_x, str_y, str_z;
    std::string input_csv_file_path = "D:\\ooc\\PointCloud.txt";
    std::ifstream ifs_csv_file(input_csv_file_path);

    double bbox[6];

    bbox[0] = bbox[1] = bbox[2] = +(std::numeric_limits<double>::max)();
    bbox[3] = bbox[4] = bbox[5] = -(std::numeric_limits<double>::max)();


    HPoint points[55000];

    // initialize preprocessor with output file
    Preprocessor preprocessor(L"D:\\ooc\\pt_cloud.ooc");

    int total_points = 0;
    int counter = 0;

    float p[3];
    while (getline(ifs_csv_file, str_buf) && total_points <=60000000)
    {
        std::istringstream i_stream(str_buf);
        getline(i_stream, str_x, ';');
        getline(i_stream, str_y, ';');
        getline(i_stream, str_z, ';');

		p[0] = std::stof(strip(str_x));
		p[1] = std::stof(strip(str_y));
		p[2] = std::stof(strip(str_z));

        total_points++;

        for (int i = 0; i < 3; ++i) {
            if (p[i] < bbox[i + 0])
                bbox[i + 0] = p[i];
            if (p[i] > bbox[i + 3])
                bbox[i + 3] = p[i];
        }
        
       // preprocessor.AddPoints(1, p);
    }

    ooc::Point culling_min((float)bbox[0], (float)bbox[1], (float)bbox[2]);
    ooc::Point culling_max((float)bbox[3], (float)bbox[4], (float)bbox[5]);
    preprocessor.SetCullingBoundingBox(culling_min, culling_max);
    preprocessor.Initialize();
    
    ifs_csv_file.close();

    total_points = 0;
    ifs_csv_file.open(input_csv_file_path);
    while (getline(ifs_csv_file, str_buf) && total_points <= 60000000)
    {
        std::istringstream i_stream(str_buf);
        getline(i_stream, str_x, ';');
        getline(i_stream, str_y, ';');
        getline(i_stream, str_z, ';');

		p[0] = std::stof(strip(str_x));
		p[1] = std::stof(strip(str_y));
		p[2] = std::stof(strip(str_z));


        total_points++;


         preprocessor.AddPoints(1, p);
    }

    preprocessor.Export();
}```