@@ -139,7 +139,6 @@ private static void ProcessAllFiles(System.Object importSettingsObject)
139
139
Stopwatch stopwatch = new Stopwatch ( ) ;
140
140
stopwatch . Start ( ) ;
141
141
142
-
143
142
// if user has set maxFiles param, loop only that many files
144
143
importSettings . maxFiles = importSettings . maxFiles > 0 ? importSettings . maxFiles : importSettings . inputFiles . Count ;
145
144
importSettings . maxFiles = Math . Min ( importSettings . maxFiles , importSettings . inputFiles . Count ) ;
@@ -150,14 +149,50 @@ private static void ProcessAllFiles(System.Object importSettingsObject)
150
149
progressFile = 0 ;
151
150
progressTotalFiles = importSettings . maxFiles - 1 ;
152
151
if ( progressTotalFiles < 0 ) progressTotalFiles = 0 ;
152
+
153
+ List < Float3 > boundsListTemp = new List < Float3 > ( ) ;
154
+
155
+ // get all file bounds, if in batch mode and RGB+INT+PACK
156
+ // TODO: check what happens if its too high? over 128/256?
157
+ if ( importSettings . useAutoOffset == true && importSettings . importIntensity == true && importSettings . importRGB == true && importSettings . packColors == true )
158
+ {
159
+ for ( int i = 0 , len = importSettings . maxFiles ; i < len ; i ++ )
160
+ {
161
+ progressFile = i ;
162
+ Log . WriteLine ( "\n Reading bounds from file (" + ( i + 1 ) + "/" + len + ") : " + importSettings . inputFiles [ i ] + " (" + Tools . HumanReadableFileSize ( new FileInfo ( importSettings . inputFiles [ i ] ) . Length ) + ")" ) ;
163
+ var res = GetBounds ( importSettings , i ) ;
164
+
165
+ if ( res . Item1 == true )
166
+ {
167
+ boundsListTemp . Add ( new Float3 ( res . Item2 , res . Item3 , res . Item4 ) ) ;
168
+ }
169
+ }
170
+
171
+ // print lowest bounds from boundsListTemp
172
+ float lowestX = float . MaxValue ;
173
+ float lowestY = float . MaxValue ;
174
+ float lowestZ = float . MaxValue ;
175
+ for ( int iii = 0 ; iii < boundsListTemp . Count ; iii ++ )
176
+ {
177
+ if ( boundsListTemp [ iii ] . x < lowestX ) lowestX = ( float ) boundsListTemp [ iii ] . x ;
178
+ if ( boundsListTemp [ iii ] . y < lowestY ) lowestY = ( float ) boundsListTemp [ iii ] . y ;
179
+ if ( boundsListTemp [ iii ] . z < lowestZ ) lowestZ = ( float ) boundsListTemp [ iii ] . z ;
180
+ }
181
+
182
+ //Console.WriteLine("Lowest bounds: " + lowestX + " " + lowestY + " " + lowestZ);
183
+ // TODO could take center for XZ, and lowest for Y
184
+ importSettings . offsetX = lowestX + 0.1f ;
185
+ importSettings . offsetY = lowestY + 0.1f ;
186
+ importSettings . offsetZ = lowestZ + 0.1f ;
187
+ }
188
+
189
+ progressFile = 0 ;
153
190
for ( int i = 0 , len = importSettings . maxFiles ; i < len ; i ++ )
154
191
{
155
192
progressFile = i ;
156
193
Log . WriteLine ( "\n Reading file (" + ( i + 1 ) + "/" + len + ") : " + importSettings . inputFiles [ i ] + " (" + Tools . HumanReadableFileSize ( new FileInfo ( importSettings . inputFiles [ i ] ) . Length ) + ")" ) ;
157
194
//Debug.WriteLine("\nReading file (" + (i + 1) + "/" + len + ") : " + importSettings.inputFiles[i] + " (" + Tools.HumanReadableFileSize(new FileInfo(importSettings.inputFiles[i]).Length) + ")");
158
-
159
195
//if (abort==true)
160
-
161
196
// do actual point cloud parsing for this file
162
197
ParseFile ( importSettings , i ) ;
163
198
}
@@ -222,6 +257,22 @@ static void ProgressTick(object sender, EventArgs e)
222
257
}
223
258
}
224
259
260
+ static ( bool , float , float , float ) GetBounds ( ImportSettings importSettings , int fileIndex )
261
+ {
262
+ var res = importSettings . reader . InitReader ( importSettings , fileIndex ) ;
263
+ if ( res == false )
264
+ {
265
+ Log . WriteLine ( "Unknown error while initializing reader: " + importSettings . inputFiles [ fileIndex ] ) ;
266
+ return ( false , 0 , 0 , 0 ) ;
267
+ }
268
+ var bounds = importSettings . reader . GetBounds ( ) ;
269
+ //Console.WriteLine(bounds.minX + " " + bounds.minY + " " + bounds.minZ);
270
+
271
+ importSettings . reader . Close ( ) ;
272
+
273
+ return ( true , bounds . minX , bounds . minY , bounds . minZ ) ;
274
+ }
275
+
225
276
// process single file
226
277
static void ParseFile ( ImportSettings importSettings , int fileIndex )
227
278
{
@@ -260,24 +311,12 @@ static void ParseFile(ImportSettings importSettings, int fileIndex)
260
311
Log . WriteLine ( "Points: " + pointCount ) ;
261
312
}
262
313
263
- // NOTE only works with formats that have bounds defined in header, otherwise need to loop whole file to get bounds
264
- var bounds = importSettings . reader . GetBounds ( ) ;
314
+ // NOTE only works with formats that have bounds defined in header, otherwise need to loop whole file to get bounds?
265
315
266
- if ( importSettings . useAutoOffset == true )
316
+ // dont use these bounds, in this case
317
+ if ( importSettings . useAutoOffset == true && importSettings . importIntensity == true && importSettings . importRGB == true && importSettings . packColors == true )
267
318
{
268
- // get offset only from the first file, other files use same offset
269
- if ( fileIndex == 0 )
270
- {
271
- // offset cloud to be near 0,0,0
272
- importSettings . offsetX = bounds . minX ;
273
- importSettings . offsetY = bounds . minY ;
274
- //importSettings.offsetZ = bounds.minZ;
275
- }
276
- // NOW smallest Y offset and largest X,Z is used (to fix INT packing negative value issue) TODO this can create more tile than old, so need to check if this is ok
277
- if ( bounds . minZ < importSettings . offsetZ )
278
- {
279
- importSettings . offsetZ = bounds . minZ ;
280
- }
319
+ // we use global bounds or Y offset to fix negative Y
281
320
}
282
321
else if ( importSettings . useManualOffset == true )
283
322
{
0 commit comments