[Liblas-devel] Error reading two Terrascan .BIN file

Suvajit suvajit at sce.co.in
Thu May 13 03:37:50 EDT 2010


Hi Howard,
Here is the function which reads two .BIN files and dumps the classification
difference into the third file.
The Header for both the streams of file1 & file2 has been read before
calling the function and also ensured that the bin files are same with equal
number of point record count .

/*
* RecordClassDiff
* args
* istream* strmI Input stream for bin file1
* istream* strmO Input stream for bin file2
* ostream* writer Output stream for diff file
* ScanHdr* hdr Scanned header of file1
* return 
* bool - true if diff generated successfully
*
*/

bool RecordClassDiff(std::istream* strmI, std::istream* strmO, std::ostream*
writer,ScanHdr* hdr){

    ScanPnt* pointI = new ScanPnt;
    ScanRow* rowI = new ScanRow;

    ScanPnt* pointO = new ScanPnt;
    ScanRow* rowO = new ScanRow;

    int index = 0;
    int count = 1;
    
    while (true)
    {
        try
            {
                std::cout << "Istream position is: " << strmI->tellg() <<
std::endl;
	  	    std::cout << "Ostream position is: " << strmO->tellg()
<< std::endl;
                if (hdr->HdrVersion == 20020715) {
			  // Read scan point from file1
                    detail::read_n(*pointI, *strmI, sizeof(ScanPnt));
			  // Read scan point from file2
			  detail::read_n(*pointO, *strmO, sizeof(ScanPnt));
                } else{
			  //read scan point for file1
                    detail::read_n(*rowI, *strmI, sizeof(ScanRow));
                    pointI->Pnt.x = rowI->x;
                    pointI->Pnt.y = rowI->y;
                    pointI->Pnt.z = rowI->z;
                    pointI = rowI->Code;
                    pointI->Line = rowI->Line;
                    pointI->Intensity = rowI->EchoInt & 0x3FFF;
                    pointI->Echo = (rowI->EchoInt >> 14);

			  //read scan point for file2
                    detail::read_n(*rowO, *strmO, sizeof(ScanRow));
                    pointO->Pnt.x = rowO->x;
                    pointO->Pnt.y = rowO->y;
                    pointO->Pnt.z = rowO->z;
                    pointO->Code = rowO->Code;
                    pointO->Line = rowO->Line;
                    pointO->Intensity = rowO->EchoInt & 0x3FFF;
                    pointO->Echo = (rowO->EchoInt >> 14);
                }

		    Classification classI = Classification(pointI->Code);
                Classification classO = Classification(pointO->Code); 
		    int classIName = classI.GetClass();
		    int classOName = classO.GetClass();

		    // Compare and record diff
		    if ( classIName != classOName ) {

		          *writer << index <<  " " <<  classIName << " " <<
classOName << " " << std::endl;
			     count++;
		     }

                // Reading remaining data to increment pointers to next
record
		    if (hdr->Time) {
                    liblas::uint32_t tI = 0xFFFFFFFF;
			  liblas::uint32_t tO = 0xFFFFFFFF;
                    detail::read_n(tI, *strmI, sizeof(tI));
                    detail::read_n(tO, *strmI, sizeof(tO));
                }
                if (hdr->Color) {
                    liblas::uint8_t rI, gI, bI, aI = 0;
  			  liblas::uint8_t rO, gO, bO, aO = 0;
                    
                    detail::read_n(rI, *strmI, sizeof(rI));
                    detail::read_n(bI, *strmI, sizeof(bI));
                    detail::read_n(gI, *strmI, sizeof(gI));
                    detail::read_n(aI, *strmI, sizeof(aI));

                    
			  detail::read_n(rO, *strmI, sizeof(rO));
                    detail::read_n(bO, *strmI, sizeof(bO));
                    detail::read_n(gO, *strmI, sizeof(gO));
                    detail::read_n(aO, *strmI, sizeof(aO));  
                }

			 
		    //Increment index
		    index++;
            }
            catch (std::out_of_range) // we reached the end of the file
            {
		    std::cout << "catching out of range error!"  <<
std::endl;
		    std::cout << "Point read  : " << index << std::endl;
		    std::cout << "Total diffs : " << count << std::endl;
                return true;
            }
            catch (std::exception const& e) // we reached the end of the
file
            {
                std::cout << e.what() << std::endl;
                break;
            }  
			
	}
	

    delete pointI;
    delete rowI;
    delete classI;
	
    delete pointO;
    delete rowO;
    delete classO;

    return true;  

}

Regards,
Suvajit Sengupta
www.sce.co.in
  
we guide your way


-----Original Message-----
From: Howard Butler [mailto:hobu.inc at gmail.com] 
Sent: Thursday, May 13, 2010 2:50 AM
To: jeet_sen
Cc: liblas-devel at lists.osgeo.org
Subject: Re: [Liblas-devel] Error reading two Terrascan .BIN file


On May 12, 2010, at 8:12 AM, jeet_sen wrote:

> 
> HI,
>  I am trying to compare two .BIN files in Windows (VS2008).  
>  Since I do not have the BIn file structure standard, I am following the
> structure as defined in ts2las.hpp available in ts2las utility.
>  As per the structure defined:
>  Header   = 56 bytes
>  ScanPnt = 24 bytes
> 
> Now to compare two files, I read the points simultaneously one after the
> other like this:
> (strmI and strmO are my two file streams containing same no of record
> points)
> 
> std::cout << "Istream position is: " << strmI->tellg() << std::endl;
> std::cout << "Ostream position is: " << strmO->tellg() << std::endl;

Is strmO an ostream or istream?

Please show more code, this isn't enough to see what's going on.





More information about the Liblas-devel mailing list