Skip to content

Commit

Permalink
Fix more cpplint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jp-pino committed Apr 30, 2024
1 parent dd33244 commit 326a59a
Show file tree
Hide file tree
Showing 24 changed files with 211 additions and 225 deletions.
4 changes: 0 additions & 4 deletions CPPLINT.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,3 @@ filter=-build/namespaces
filter=-whitespace/braces
filter=-build/include_subdir
filter=-readability/todo


# Should consider re-enabling
filter=-whitespace/parens
5 changes: 1 addition & 4 deletions include/oculus_driver/AsyncService.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*****************************************************************************/

#ifndef _DEF_OCULUS_DRIVER_ASYNC_SERVICE_H_
#define _DEF_OCULUS_DRIVER_ASYNC_SERVICE_H_
#pragma once

#include <iostream>
#include <thread>
Expand Down Expand Up @@ -53,5 +52,3 @@ class AsyncService
};

} // namespace oculus

#endif //_DEF_OCULUS_DRIVER_ASYNC_SERVICE_H_
5 changes: 1 addition & 4 deletions include/oculus_driver/Clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*****************************************************************************/

#ifndef _DEF_OCULUS_DRIVER_CLOCK_H_
#define _DEF_OCULUS_DRIVER_CLOCK_H_
#pragma once

#include <iostream>
#include <chrono>
Expand Down Expand Up @@ -73,5 +72,3 @@ inline std::ostream& operator<<(std::ostream& os, const oculus::Clock& clock)
os << clock.now() << "s";
return os;
}

#endif //_DEF_OCULUS_DRIVER_CLOCK_H_
37 changes: 17 additions & 20 deletions include/oculus_driver/OculusMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*****************************************************************************/

#ifndef _DEF_OCULUS_DRIVER_OCULUS_MESSAGE_H_
#define _DEF_OCULUS_DRIVER_OCULUS_MESSAGE_H_
#pragma once

#include "oculus_driver/Oculus.h"
#include "oculus_driver/utils.h"
Expand Down Expand Up @@ -104,7 +103,7 @@ class Message
{
OculusMessageHeader header;
std::memcpy(&header, data, sizeof(OculusMessageHeader));
if(!header_valid(header) || size != header.payloadSize + sizeof(OculusMessageHeader)) { return nullptr; }
if (!header_valid(header) || size != header.payloadSize + sizeof(OculusMessageHeader)) { return nullptr; }
auto res = Create();
res->header_ = header;
res->timestamp_ = stamp;
Expand Down Expand Up @@ -169,8 +168,8 @@ class PingWrapper
PingWrapper(const Message::ConstPtr& msg)
: msg_(msg)
{
if(!msg_) { throw std::runtime_error("Trying to make a PingMessage out of empty data."); }
if(!msg_->is_ping_message()) { throw std::runtime_error("Trying to make a PingMessage out of non-ping data."); }
if (!msg_) { throw std::runtime_error("Trying to make a PingMessage out of empty data."); }
if (!msg_->is_ping_message()) { throw std::runtime_error("Trying to make a PingMessage out of non-ping data."); }
}

public:
Expand Down Expand Up @@ -235,7 +234,7 @@ class PingWrapper1 : public PingWrapper
PingWrapper1(const Message::ConstPtr& msg)
: PingWrapper(msg)
{
if(msg->message_version() == 2)
if (msg->message_version() == 2)
{
throw std::runtime_error("Tried to initialize a PingWrapper1 with data from a PingWrapper2");
}
Expand Down Expand Up @@ -295,7 +294,7 @@ class PingWrapper1 : public PingWrapper

virtual uint8_t sample_size() const
{
switch(this->metadata().dataSize)
switch (this->metadata().dataSize)
{
case ImageData8Bit:
return 1;
Expand All @@ -308,11 +307,11 @@ class PingWrapper1 : public PingWrapper
default:
// invalid value in metadata.dataSize. Deducing from message size.
auto lineStep = this->metadata().imageSize / this->metadata().nRanges;
if(lineStep * this->metadata().nRanges != this->metadata().imageSize) { return 0; }
if(this->has_gains()) lineStep -= 4;
if (lineStep * this->metadata().nRanges != this->metadata().imageSize) { return 0; }
if (this->has_gains()) lineStep -= 4;
auto sampleSize = lineStep / this->metadata().nBeams;
// Checking integrity
if(sampleSize * this->metadata().nBeams != lineStep) { return 0; }
if (sampleSize * this->metadata().nBeams != lineStep) { return 0; }
return sampleSize;
}
}
Expand Down Expand Up @@ -388,7 +387,7 @@ class PingWrapper2 : public PingWrapper
PingWrapper2(const Message::ConstPtr& msg)
: PingWrapper(msg)
{
if(msg->message_version() != 2)
if (msg->message_version() != 2)
{
throw std::runtime_error("Tried to initialize a PingWrapper2 with data from a PingWrapper1");
}
Expand Down Expand Up @@ -449,7 +448,7 @@ class PingWrapper2 : public PingWrapper

virtual uint8_t sample_size() const
{
switch(this->metadata().dataSize)
switch (this->metadata().dataSize)
{
case ImageData8Bit:
return 1;
Expand All @@ -462,11 +461,11 @@ class PingWrapper2 : public PingWrapper
default:
// invalid value in metadata.dataSize. Deducing from message size.
auto lineStep = this->metadata().imageSize / this->metadata().nRanges;
if(lineStep * this->metadata().nRanges != this->metadata().imageSize) { return 0; }
if(this->has_gains()) lineStep -= 4;
if (lineStep * this->metadata().nRanges != this->metadata().imageSize) { return 0; }
if (this->has_gains()) lineStep -= 4;
auto sampleSize = lineStep / this->metadata().nBeams;
// Checking integrity
if(sampleSize * this->metadata().nBeams != lineStep) { return 0; }
if (sampleSize * this->metadata().nBeams != lineStep) { return 0; }
return sampleSize;
}
}
Expand Down Expand Up @@ -543,8 +542,8 @@ class PingMessage

static PingWrapper::Ptr make_ping_wrapper(const Message::ConstPtr& msg)
{
if(!msg || !msg->is_ping_message()) { return nullptr; }
if(msg->message_version() == 2) { return PingWrapper2::Create(msg); }
if (!msg || !msg->is_ping_message()) { return nullptr; }
if (msg->message_version() == 2) { return PingWrapper2::Create(msg); }
else { return PingWrapper1::Create(msg); }
}

Expand All @@ -567,7 +566,7 @@ class PingMessage
{
OculusMessageHeader header;
std::memcpy(&header, data, sizeof(OculusMessageHeader));
if(!is_ping_message(header) || size != header.payloadSize + sizeof(OculusMessageHeader)) { return nullptr; }
if (!is_ping_message(header) || size != header.payloadSize + sizeof(OculusMessageHeader)) { return nullptr; }
return Create(Message::Create(size, data, stamp));
}

Expand Down Expand Up @@ -708,5 +707,3 @@ class PingMessage
};

} // namespace oculus

#endif //_DEF_OCULUS_DRIVER_OCULUS_MESSAGE_H_
50 changes: 25 additions & 25 deletions include/oculus_driver/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ inline void write_pgm(const std::string& filename,
const uint8_t* data)
{
std::ofstream f(filename, std::ios::out | std::ios::binary);
if(!f.is_open()) {
if (!f.is_open()) {
std::ostringstream oss;
oss << "Could not open file for writing : " << filename;
throw std::runtime_error(oss.str());
Expand All @@ -33,15 +33,15 @@ inline void write_pgm(const std::string& filename,
{
float m = data[0];
float M = data[0];
for(unsigned int i = 0; i < width*height; i++) {
for (unsigned int i = 0; i < width*height; i++) {
m = std::min(m, data[i]);
M = std::max(M, data[i]);
}

float a = 255.0 / (M - m);
float b = -m * a;
std::vector<uint8_t> imageData(width*height);
for(unsigned int i = 0; i < width*height; i++) {
for (unsigned int i = 0; i < width*height; i++) {
imageData[i] = a*data[i] + b;
}
write_pgm(filename, width, height, imageData.data());
Expand Down Expand Up @@ -121,42 +121,42 @@ inline void ping_data_to_array(T* dst,
const OculusPingResultType& metadata,
const std::vector<uint8_t>& pingData)
{
if(has_16bits_data(metadata)) {
if (has_16bits_data(metadata)) {
auto data = (const uint16_t*)(pingData.data() + metadata.imageOffset);
if(has_gains(metadata)) {
if (has_gains(metadata)) {
// gain is sent
for(unsigned int h = 0; h < metadata.nRanges; h++) {
for (unsigned int h = 0; h < metadata.nRanges; h++) {
float gain = 1.0f / sqrt((float)((const uint32_t*)data)[0]);
data += 2;
for(int w = 0; w < metadata.nBeams; w++) {
for (int w = 0; w < metadata.nBeams; w++) {
dst[metadata.nBeams*w + h] = gain * data[w];
}
data += metadata.nBeams;
}
}
else {
//gain was not sent
for(unsigned int i = 0; i < metadata.nBeams*metadata.nRanges; i++) {
// gain was not sent
for (unsigned int i = 0; i < metadata.nBeams*metadata.nRanges; i++) {
dst[i] = data[i];
}
}
}
else {
auto data = (const uint8_t*)(pingData.data() + metadata.imageOffset);
if(has_gains(metadata)) {
if (has_gains(metadata)) {
// gain is sent
for(unsigned int h = 0; h < metadata.nRanges; h++) {
for (unsigned int h = 0; h < metadata.nRanges; h++) {
float gain = 1.0f / sqrt((float)((const uint32_t*)data)[0]);
data += 4;
for(int w = 0; w < metadata.nBeams; w++) {
for (int w = 0; w < metadata.nBeams; w++) {
dst[metadata.nBeams*w + h] = gain * data[w];
}
data += metadata.nBeams;
}
}
else {
//gain was not sent
for(unsigned int i = 0; i < metadata.nBeams*metadata.nRanges; i++) {
// gain was not sent
for (unsigned int i = 0; i < metadata.nBeams*metadata.nRanges; i++) {
dst[i] = data[i];
}
}
Expand All @@ -165,10 +165,10 @@ inline void ping_data_to_array(T* dst,
inline std::vector<float> get_ping_acoustic_data(const std::vector<uint8_t>& pingData)
{
auto header = *reinterpret_cast<const OculusMessageHeader*>(pingData.data());
if(header.msgId != MsgSimplePingResult) {
if (header.msgId != MsgSimplePingResult) {
throw std::runtime_error("Not a ping result");
}
if(header.msgVersion != 2) {
if (header.msgVersion != 2) {
auto metadata = *reinterpret_cast<const OculusSimplePingResult*>(pingData.data());
std::vector<float> dst(metadata.nBeams * metadata.nRanges);
ping_data_to_array(dst.data(), metadata, pingData);
Expand All @@ -192,17 +192,17 @@ inline void get_ping_bearings(T* dst,
{
// copying bearing angles (
auto bearingData = (const int16_t*)(pingData.data() + sizeof(OculusPingResultType));
for(unsigned int i = 0; i < metadata.nBeams; i++) {
for (unsigned int i = 0; i < metadata.nBeams; i++) {
dst[i] = (0.01 * M_PI / 180.0) * bearingData[i];
}
}
inline std::vector<float> get_ping_bearings(const std::vector<uint8_t>& pingData)
{
auto header = *reinterpret_cast<const OculusMessageHeader*>(pingData.data());
if(header.msgId != MsgSimplePingResult) {
if (header.msgId != MsgSimplePingResult) {
throw std::runtime_error("Not a ping result");
}
if(header.msgVersion != 2) {
if (header.msgVersion != 2) {
auto metadata = *reinterpret_cast<const OculusSimplePingResult*>(pingData.data());
std::vector<float> dst(metadata.nBeams);
get_ping_bearings(dst.data(), metadata, pingData);
Expand Down Expand Up @@ -249,14 +249,14 @@ inline std::pair<unsigned int, unsigned int> image_from_ping_data(
// Making a lookup table to rapidly get bearing index from a bearing angle.
// This comes down to performing a nearest neighbour interpolation.
std::vector<unsigned int> bearingLut(metadata.nBeams);
for(unsigned int b = 0; b < metadata.nBeams; b++) {
for (unsigned int b = 0; b < metadata.nBeams; b++) {
float bearingAngle = ((bearings.back() - bearings.front())*b) / (metadata.nBeams - 1)
+ bearings.front();
unsigned int idx = 0;
float minDiff = std::abs(bearings[0] - bearingAngle);
for(int i = 1; i <bearings.size(); i++) {
for (int i = 1; i <bearings.size(); i++) {
float diff = std::abs(bearings[i] - bearingAngle);
if(diff < minDiff) {
if (diff < minDiff) {
minDiff = diff;
idx = i;
}
Expand All @@ -269,14 +269,14 @@ inline std::pair<unsigned int, unsigned int> image_from_ping_data(
// and y positive is right direction.
// In the image coordinates, x points to the top and y points to the right.
float imageResolution = get_range(metadata) / (height - 1);
for(unsigned int h = 0; h < height; h++) {
for (unsigned int h = 0; h < height; h++) {
// inverting x dimension to have origin at the bottom a x up.
float x = imageResolution * (height - 1 - h);
for(unsigned int w = 0; w < width; w++) {
for (unsigned int w = 0; w < width; w++) {
float y = imageResolution * (w - 0.5f*width);
float range = sqrt(x*x + y*y);
float bearing = std::atan2(y, x);
if(range < 0.0f || range > get_range(metadata) || abs(bearing) > 0.5f*aperture) {
if (range < 0.0f || range > get_range(metadata) || abs(bearing) > 0.5f*aperture) {
// we are outside of the sonar fan
imageData[width*h + w] = 0.0f;
}
Expand Down
14 changes: 7 additions & 7 deletions include/oculus_driver/rtac_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@ inline void oculus_to_rtac(SonarPing2D<T,VectorT>& dst,
// using intermediary std::vector in case VectorT is not directly
// writable (such as rtac::cuda::DeviceVector)
std::vector<float> bearings(metadata.nBeams);
for(unsigned int i = 0; i < bearings.size(); i++) {
for (unsigned int i = 0; i < bearings.size(); i++) {
bearings[i] = (0.01 * M_PI / 180.0) * bearingData[i];
}
dst.set_bearings(bearings);

//copying ping data
// copying ping data
std::vector<T> pingData(dst.size());
const uint8_t* data = data.data() + metadata.imageOffset;
if(metadata.fireMessage.flags & 0x04) {
if (metadata.fireMessage.flags & 0x04) {
// gain is sent
for(unsigned int h = 0; h < dst.range_count(); h++) {
for (unsigned int h = 0; h < dst.range_count(); h++) {
float gain = 1.0f * sqrt((float)((const uint32_t*)data)[0]);
data += 4;
for(int w = 0; w < dst.bearing_count; w++) {
for (int w = 0; w < dst.bearing_count; w++) {
pingData[dst.bearing_count()*w + h] = data[w];
}
data += dst.bearing_count();
}
}
else {
//gain was not sent
for(int i = 0; i < pingData.size(); i++) {
// gain was not sent
for (int i = 0; i < pingData.size(); i++) {
pingData[i] = data[i] / 255.0;
}
}
Expand Down
Loading

0 comments on commit 326a59a

Please sign in to comment.