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

jeet_sen suvajit at sce.co.in
Thu May 13 03:39:09 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

-- 
View this message in context: http://liblas-developers.431198.n3.nabble.com/Error-reading-two-Terrascan-BIN-file-tp812436p814363.html
Sent from the libLAS Developers mailing list archive at Nabble.com.


More information about the Liblas-devel mailing list