boofcv.alg.cloud.PointCloudWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of boofcv-geo Show documentation
Show all versions of boofcv-geo Show documentation
BoofCV is an open source Java library for real-time computer vision and robotics applications.
/*
* Copyright (c) 2022, Peter Abeles. All Rights Reserved.
*
* This file is part of BoofCV (http://boofcv.org).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package boofcv.alg.cloud;
import boofcv.struct.Point3dRgbI_F32;
import boofcv.struct.Point3dRgbI_F64;
import georegression.struct.point.Point3D_F32;
import georegression.struct.point.Point3D_F64;
import org.ddogleg.struct.DogArray;
import org.ddogleg.struct.DogArray_F32;
import org.ddogleg.struct.DogArray_I32;
/**
* Interface for reading a point cloud
*
* @author Peter Abeles
*/
public interface PointCloudWriter {
/**
* Initializes and passes in configurations.
*
* @param size Estimated size of the point cloud. Passes in a value ≤ 0 if it's unknown
* @param hasColor true if the cloud has color information
*/
void initialize( int size, boolean hasColor );
/**
* Adds a 3D point with color information
*/
void add( double x, double y, double z, int rgb );
class CloudArraysF32 implements PointCloudWriter {
// Storage for point cloud
public DogArray_F32 cloudXyz = new DogArray_F32();
public DogArray_I32 cloudRgb = new DogArray_I32();
@Override public void initialize( int size, boolean hasColor ) {
cloudRgb.reset();
cloudXyz.reset();
cloudRgb.reserve(size);
cloudXyz.reserve(size*3);
}
@Override public void add( double x, double y, double z, int rgb ) {
cloudXyz.add((float)x);
cloudXyz.add((float)y);
cloudXyz.add((float)z);
cloudRgb.add(rgb);
}
public void getPoint( int index, Point3D_F64 p ) {
int i = index*3;
p.x = cloudXyz.data[i];
p.y = cloudXyz.data[i + 1];
p.z = cloudXyz.data[i + 2];
}
}
static PointCloudWriter wrapF32( DogArray cloud ) {
return new PointCloudWriter() {
@Override public void initialize( int size, boolean hasColor ) {
cloud.reserve(size);
cloud.reset();
}
@Override
public void add( double x, double y, double z, int rgb ) {
cloud.grow().setTo((float)x, (float)y, (float)z);
}
};
}
static PointCloudWriter wrapF64( DogArray cloud ) {
return new PointCloudWriter() {
@Override public void initialize( int size, boolean hasColor ) {
cloud.reserve(size);
cloud.reset();
}
@Override
public void add( double x, double y, double z, int rgb ) {
cloud.grow().setTo(x, y, z);
}
};
}
static PointCloudWriter wrapF32RGB( DogArray cloud ) {
return new PointCloudWriter() {
@Override public void initialize( int size, boolean hasColor ) {
cloud.reserve(size);
cloud.reset();
}
@Override
public void add( double x, double y, double z, int rgb ) {
cloud.grow().setTo((float)x, (float)y, (float)z, rgb);
}
};
}
static PointCloudWriter wrapF64RGB( DogArray cloud ) {
return new PointCloudWriter() {
@Override public void initialize( int size, boolean hasColor ) {
cloud.reset();
}
@Override
public void add( double x, double y, double z, int rgb ) {
cloud.grow().setTo(x, y, z, rgb);
}
};
}
}