Skip to content

Commit

Permalink
Use C++ style casts
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Laing committed Jun 17, 2018
1 parent 5f2a48d commit c0c6ee1
Show file tree
Hide file tree
Showing 69 changed files with 147 additions and 147 deletions.
2 changes: 1 addition & 1 deletion src/draco/attributes/attribute_octahedron_transform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ AttributeOctahedronTransform::GeneratePortableAttribute(
DRACO_DCHECK(is_initialized());

// Allocate portable attribute.
const int num_entries = (int)point_ids.size();
const int num_entries = static_cast<int>(point_ids.size());
std::unique_ptr<PointAttribute> portable_attribute =
InitPortableAttribute(num_entries, 2, num_points, attribute, true);

Expand Down
4 changes: 2 additions & 2 deletions src/draco/attributes/attribute_quantization_transform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ bool AttributeQuantizationTransform::ComputeParameters(
attribute.GetValue(AttributeValueIndex(0), min_values_.data());
attribute.GetValue(AttributeValueIndex(0), max_values.get());

for (AttributeValueIndex i(1); i < (uint32_t)attribute.size(); ++i) {
for (AttributeValueIndex i(1); i < static_cast<uint32_t>(attribute.size()); ++i) {
attribute.GetValue(i, att_val.get());
for (int c = 0; c < num_components; ++c) {
if (min_values_[c] > att_val[c])
Expand Down Expand Up @@ -144,7 +144,7 @@ AttributeQuantizationTransform::GeneratePortableAttribute(
DRACO_DCHECK(is_initialized());

// Allocate portable attribute.
const int num_entries = (int)point_ids.size();
const int num_entries = static_cast<int>(point_ids.size());
const int num_components = attribute.num_components();
std::unique_ptr<PointAttribute> portable_attribute = InitPortableAttribute(
num_entries, num_components, num_points, attribute, true);
Expand Down
2 changes: 1 addition & 1 deletion src/draco/attributes/attribute_transform_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class AttributeTransformData {
// Sets a parameter value at the end of the |buffer_|.
template <typename DataTypeT>
void AppendParameterValue(const DataTypeT &in_data) {
SetParameterValue((int)buffer_.data_size(), in_data);
SetParameterValue(static_cast<int>(buffer_.data_size()), in_data);
}

private:
Expand Down
4 changes: 2 additions & 2 deletions src/draco/attributes/point_attribute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ bool PointAttribute::Reset(size_t num_attribute_values) {
return false;
// Assign the new buffer to the parent attribute.
ResetBuffer(attribute_buffer_.get(), entry_size, 0);
num_unique_entries_ = (uint32_t)num_attribute_values;
num_unique_entries_ = static_cast<uint32_t>(num_attribute_values);
return true;
}

Expand Down Expand Up @@ -193,7 +193,7 @@ AttributeValueIndex::ValueType PointAttribute::DeduplicateFormattedValues(
}
} else {
// Update point to value map using the mapping between old and new values.
for (PointIndex i(0); i < (uint32_t)indices_map_.size(); ++i) {
for (PointIndex i(0); i < static_cast<uint32_t>(indices_map_.size()); ++i) {
SetPointMapEntry(i, value_map[indices_map_[i]]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/draco/attributes/point_attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class PointAttribute : public GeometryAttribute {

// Sets the new number of unique attribute entries for the attribute.
void Resize(size_t new_num_unique_entries) {
num_unique_entries_ = (uint32_t)new_num_unique_entries;
num_unique_entries_ = static_cast<uint32_t>(new_num_unique_entries);
}

// Functions for setting the type of mapping between point indices and
Expand Down
4 changes: 2 additions & 2 deletions src/draco/compression/attributes/attributes_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class AttributesDecoder : public AttributesDecoderInterface {
return point_attribute_ids_[i];
}
int32_t GetNumAttributes() const override {
return (int32_t)point_attribute_ids_.size();
return static_cast<int32_t>(point_attribute_ids_.size());
}
PointCloudDecoder *GetDecoder() const override {
return point_cloud_decoder_;
Expand All @@ -65,7 +65,7 @@ class AttributesDecoder : public AttributesDecoderInterface {

protected:
int32_t GetLocalIdForPointAttribute(int32_t point_attribute_id) const {
const int id_map_size = (int)point_attribute_to_local_id_map_.size();
const int id_map_size = static_cast<int>(point_attribute_to_local_id_map_.size());
if (point_attribute_id >= id_map_size)
return -1;
return point_attribute_to_local_id_map_[point_attribute_id];
Expand Down
6 changes: 3 additions & 3 deletions src/draco/compression/attributes/attributes_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class AttributesEncoder {
point_attribute_ids_.push_back(id);
if (id >= static_cast<int32_t>(point_attribute_to_local_id_map_.size()))
point_attribute_to_local_id_map_.resize(id + 1, -1);
point_attribute_to_local_id_map_[id] = (int32_t)point_attribute_ids_.size() - 1;
point_attribute_to_local_id_map_[id] = static_cast<int32_t>(point_attribute_ids_.size()) - 1;
}

// Sets new attribute point ids (replacing the existing ones).
Expand All @@ -102,7 +102,7 @@ class AttributesEncoder {
}

int32_t GetAttributeId(int i) const { return point_attribute_ids_[i]; }
uint32_t num_attributes() const { return (uint32_t)point_attribute_ids_.size(); }
uint32_t num_attributes() const { return static_cast<uint32_t>(point_attribute_ids_.size()); }
PointCloudEncoder *encoder() const { return point_cloud_encoder_; }

protected:
Expand All @@ -122,7 +122,7 @@ class AttributesEncoder {
}

int32_t GetLocalIdForPointAttribute(int32_t point_attribute_id) const {
const int id_map_size = (int)point_attribute_to_local_id_map_.size();
const int id_map_size = static_cast<int>(point_attribute_to_local_id_map_.size());
if (point_attribute_id >= id_map_size)
return -1;
return point_attribute_to_local_id_map_[point_attribute_id];
Expand Down
10 changes: 5 additions & 5 deletions src/draco/compression/attributes/kd_tree_attributes_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class PointAttributeVectorOutputIterator {
data_source = reinterpret_cast<uint32_t *>(data_);
}
const AttributeValueIndex avi = attribute->mapped_index(point_id_);
if (avi >= (uint32_t)attribute->size())
if (avi >= static_cast<uint32_t>(attribute->size()))
return *this;
attribute->SetAttributeValue(avi, data_source);
}
Expand Down Expand Up @@ -268,7 +268,7 @@ bool KdTreeAttributesDecoder::DecodeDataNeededByPortableTransforms(
AttributeQuantizationTransform transform;
transform.SetParameters(quantization_bits, min_value.data(),
num_components, max_value_dif);
const int num_transforms = (int)attribute_quantization_transforms_.size();
const int num_transforms = static_cast<int>(attribute_quantization_transforms_.size());
if (!transform.TransferToAttribute(
quantized_portable_attributes_[num_transforms].get()))
return false;
Expand All @@ -290,7 +290,7 @@ bool KdTreeAttributesDecoder::DecodeDataNeededByPortableTransforms(
const uint32_t attribute_count = GetNumAttributes();
uint32_t total_dimensionality = 0; // position is a required dimension
std::vector<AttributeTuple> atts(attribute_count);
for (auto attribute_index = 0; (uint32_t)attribute_index < attribute_count;
for (auto attribute_index = 0; static_cast<uint32_t>(attribute_index) < attribute_count;
attribute_index += 1) // increment the dimensionality as needed...
{
const int att_id = GetAttributeId(attribute_index);
Expand Down Expand Up @@ -337,7 +337,7 @@ bool KdTreeAttributesDecoder::DecodeDataNeededByPortableTransforms(
if (!in_buffer->Decode(&num_points))
return false;

for (auto attribute_index = 0; (uint32_t)attribute_index < attribute_count;
for (auto attribute_index = 0; static_cast<uint32_t>(attribute_index) < attribute_count;
attribute_index += 1) {
const int att_id = GetAttributeId(attribute_index);
PointAttribute *const attr =
Expand Down Expand Up @@ -411,7 +411,7 @@ bool KdTreeAttributesDecoder::TransformAttributeBackToSignedType(
std::vector<UnsignedType> unsigned_val(att->num_components());
std::vector<SignedDataTypeT> signed_val(att->num_components());

for (AttributeValueIndex avi(0); avi < (uint32_t)att->size(); ++avi) {
for (AttributeValueIndex avi(0); avi < static_cast<uint32_t>(att->size()); ++avi) {
att->GetValue(avi, &unsigned_val[0]);
for (int c = 0; c < att->num_components(); ++c) {
// Up-cast |unsigned_val| to int32_t to ensure we don't overflow it for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ bool KdTreeAttributesEncoder::TransformAttributesToPortableFormat() {
// the actual encoding of the data.
quantized_portable_attributes_.push_back(
attribute_quantization_transform.GeneratePortableAttribute(
*att, (int)num_points));
*att, static_cast<int>(num_points)));
} else if (att->data_type() == DT_INT32 || att->data_type() == DT_INT16 ||
att->data_type() == DT_INT8) {
// For signed types, find the minimum value for each component. These
Expand All @@ -87,7 +87,7 @@ bool KdTreeAttributesEncoder::TransformAttributesToPortableFormat() {
std::vector<int32_t> min_value(att->num_components(),
std::numeric_limits<int32_t>::max());
std::vector<int32_t> act_value(att->num_components());
for (AttributeValueIndex avi(0); avi < (uint32_t)att->size(); ++avi) {
for (AttributeValueIndex avi(0); avi < static_cast<uint32_t>(att->size()); ++avi) {
att->ConvertValue<int32_t>(avi, &act_value[0]);
for (int c = 0; c < att->num_components(); ++c) {
if (min_value[c] > act_value[c])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MeshTraversalSequencer : public PointsSequencer {
attribute->SetExplicitMapping(mesh_->num_points());
const size_t num_faces = mesh_->num_faces();
const size_t num_points = mesh_->num_points();
for (FaceIndex f(0); f < (uint32_t)num_faces; ++f) {
for (FaceIndex f(0); f < static_cast<uint32_t>(num_faces); ++f) {
const auto &face = mesh_->face(f);
for (int p = 0; p < 3; ++p) {
const PointIndex point_id = face[p];
Expand Down
4 changes: 2 additions & 2 deletions src/draco/compression/attributes/normal_compression_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ class OctahedronToolBox {
if (abs_sum == 0) {
vec[0] = center_value_; // vec[1] == v[2] == 0
} else {
vec[0] = (static_cast<int64_t>((int64_t)vec[0]) * (int64_t)center_value_) / abs_sum;
vec[1] = (static_cast<int64_t>((int64_t)vec[1]) * (int64_t)center_value_) / abs_sum;
vec[0] = (static_cast<int64_t>(vec[0]) * static_cast<int64_t>(center_value_)) / abs_sum;
vec[1] = (static_cast<int64_t>(vec[1]) * static_cast<int64_t>(center_value_)) / abs_sum;
if (vec[2] >= 0) {
vec[2] = center_value_ - std::abs(vec[0]) - std::abs(vec[1]);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ bool MeshPredictionSchemeConstrainedMultiParallelogramDecoder<
// Used to store predicted value for multi-parallelogram prediction.
std::vector<DataTypeT> multi_pred_vals(num_components);

const int corner_map_size = (int)this->mesh_data().data_to_corner_map()->size();
const int corner_map_size = static_cast<int>(this->mesh_data().data_to_corner_map()->size());
for (int p = 1; p < corner_map_size; ++p) {
const CornerIndex start_corner_id =
this->mesh_data().data_to_corner_map()->at(p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ class MeshPredictionSchemeConstrainedMultiParallelogramEncoder
// TODO(ostava): This should be generalized in case we use other binary
// coding scheme.
const double entropy = ComputeBinaryShannonEntropy(
(uint32_t)total_parallelogram, (uint32_t)total_used_parallelograms);
static_cast<uint32_t>(total_parallelogram), static_cast<uint32_t>(total_used_parallelograms));

// Round up to the nearest full bit.
return (int64_t)ceil((double)total_parallelogram * entropy);
return static_cast<int64_t>(ceil(static_cast<double>(total_parallelogram) * entropy));
}

// Struct that contains data used for measuring the error of each available
Expand Down Expand Up @@ -209,7 +209,7 @@ bool MeshPredictionSchemeConstrainedMultiParallelogramEncoder<
// We start processing the vertices from the end because this prediction uses
// data from previous entries that could be overwritten when an entry is
// processed.
for (int p = (int)this->mesh_data().data_to_corner_map()->size() - 1; p > 0; --p) {
for (int p = static_cast<int>(this->mesh_data().data_to_corner_map()->size()) - 1; p > 0; --p) {
const CornerIndex start_corner_id =
this->mesh_data().data_to_corner_map()->at(p);

Expand Down Expand Up @@ -386,7 +386,7 @@ bool MeshPredictionSchemeConstrainedMultiParallelogramEncoder<
// Encode the crease edge flags in the reverse vertex order that is needed
// be the decoder. Note that for the currently supported mode, each vertex
// has exactly |num_used_parallelograms| edges that need to be encoded.
for (int j = (int)(is_crease_edge_[i].size() - num_used_parallelograms); j >= 0;
for (int j = static_cast<int>(is_crease_edge_[i].size()) - num_used_parallelograms; j >= 0;
j -= num_used_parallelograms) {
// Go over all edges of the current vertex.
for (int k = 0; k < num_used_parallelograms; ++k) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ bool MeshPredictionSchemeGeometricNormalDecoder<
// Expecting in_data in octahedral coordinates, i.e., portable attribute.
DRACO_DCHECK_EQ(num_components, 2);

const int corner_map_size = (int)this->mesh_data().data_to_corner_map()->size();
const int corner_map_size = static_cast<int>(this->mesh_data().data_to_corner_map()->size());

VectorD<int32_t, 3> pred_normal_3d;
int32_t pred_normal_oct[2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ bool MeshPredictionSchemeGeometricNormalEncoder<DataTypeT, TransformT,

flip_normal_bit_encoder_.StartEncoding();

const int corner_map_size = (int)this->mesh_data().data_to_corner_map()->size();
const int corner_map_size = static_cast<int>(this->mesh_data().data_to_corner_map()->size());

VectorD<int32_t, 3> pred_normal_3d;
VectorD<int32_t, 2> pos_pred_normal_oct;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class MeshPredictionSchemeGeometricNormalPredictorArea
// Convert to int32_t, make sure entries are not too large.
constexpr int64_t upper_bound = 1 << 29;
if (this->normal_prediction_mode_ == ONE_TRIANGLE) {
const int32_t abs_sum = (int32_t)normal.AbsSum();
const int32_t abs_sum = static_cast<int32_t>(normal.AbsSum());
if (abs_sum > upper_bound) {
const int64_t quotient = abs_sum / upper_bound;
normal = normal / quotient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ bool MeshPredictionSchemeMultiParallelogramDecoder<DataTypeT, TransformT,
const std::vector<int32_t> *const vertex_to_data_map =
this->mesh_data().vertex_to_data_map();

const int corner_map_size = (int)this->mesh_data().data_to_corner_map()->size();
const int corner_map_size = static_cast<int>(this->mesh_data().data_to_corner_map()->size());
for (int p = 1; p < corner_map_size; ++p) {
const CornerIndex start_corner_id =
this->mesh_data().data_to_corner_map()->at(p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ bool MeshPredictionSchemeMultiParallelogramEncoder<DataTypeT, TransformT,

// We start processing from the end because this prediction uses data from
// previous entries that could be overwritten when an entry is processed.
for (int p = (int)(this->mesh_data().data_to_corner_map()->size() - 1); p > 0; --p) {
for (int p = static_cast<int>(this->mesh_data().data_to_corner_map()->size() - 1); p > 0; --p) {
const CornerIndex start_corner_id =
this->mesh_data().data_to_corner_map()->at(p);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ bool MeshPredictionSchemeParallelogramDecoder<DataTypeT, TransformT,
// Restore the first value.
this->transform().ComputeOriginalValue(pred_vals.get(), in_corr, out_data);

const int corner_map_size = (int)this->mesh_data().data_to_corner_map()->size();
const int corner_map_size = static_cast<int>(this->mesh_data().data_to_corner_map()->size());
for (int p = 1; p < corner_map_size; ++p) {
const CornerIndex corner_id = this->mesh_data().data_to_corner_map()->at(p);
const int dst_offset = p * num_components;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ bool MeshPredictionSchemeParallelogramEncoder<DataTypeT, TransformT,
const CornerTable *const table = this->mesh_data().corner_table();
const std::vector<int32_t> *const vertex_to_data_map =
this->mesh_data().vertex_to_data_map();
for (int p = (int)(this->mesh_data().data_to_corner_map()->size() - 1); p > 0; --p) {
for (int p = static_cast<int>(this->mesh_data().data_to_corner_map()->size() - 1); p > 0; --p) {
const CornerIndex corner_id = this->mesh_data().data_to_corner_map()->at(p);
const int dst_offset = p * num_components;
if (!ComputeParallelogramPrediction(p, corner_id, table,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class MeshPredictionSchemeTexCoordsDecoder

Vector2f GetTexCoordForEntryId(int entry_id, const DataTypeT *data) const {
const int data_offset = entry_id * num_components_;
return Vector2f((float)data[data_offset], (float)data[data_offset + 1]);
return Vector2f(static_cast<float>(data[data_offset]), static_cast<float>(data[data_offset + 1]));
}

void ComputePredictedValue(CornerIndex corner_id, const DataTypeT *data,
Expand All @@ -124,7 +124,7 @@ bool MeshPredictionSchemeTexCoordsDecoder<DataTypeT, TransformT, MeshDataT>::
std::unique_ptr<DataTypeT[]>(new DataTypeT[num_components]);
this->transform().Initialize(num_components);

const int corner_map_size = (int)this->mesh_data().data_to_corner_map()->size();
const int corner_map_size = static_cast<int>(this->mesh_data().data_to_corner_map()->size());
for (int p = 0; p < corner_map_size; ++p) {
const CornerIndex corner_id = this->mesh_data().data_to_corner_map()->at(p);
ComputePredictedValue(corner_id, out_data, p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class MeshPredictionSchemeTexCoordsEncoder

Vector2f GetTexCoordForEntryId(int entry_id, const DataTypeT *data) const {
const int data_offset = entry_id * num_components_;
return Vector2f((float)data[data_offset], (float)data[data_offset + 1]);
return Vector2f(static_cast<float>(data[data_offset]), static_cast<float>(data[data_offset + 1]));
}

void ComputePredictedValue(CornerIndex corner_id, const DataTypeT *data,
Expand All @@ -117,7 +117,7 @@ bool MeshPredictionSchemeTexCoordsEncoder<DataTypeT, TransformT, MeshDataT>::
this->transform().Initialize(in_data, size, num_components);
// We start processing from the end because this prediction uses data from
// previous entries that could be overwritten when an entry is processed.
for (int p = (int)this->mesh_data().data_to_corner_map()->size() - 1; p >= 0;
for (int p = static_cast<int>(this->mesh_data().data_to_corner_map()->size()) - 1; p >= 0;
--p) {
const CornerIndex corner_id = this->mesh_data().data_to_corner_map()->at(p);
ComputePredictedValue(corner_id, in_data, p);
Expand All @@ -133,7 +133,7 @@ template <typename DataTypeT, class TransformT, class MeshDataT>
bool MeshPredictionSchemeTexCoordsEncoder<DataTypeT, TransformT, MeshDataT>::
EncodePredictionData(EncoderBuffer *buffer) {
// Encode the delta-coded orientations using arithmetic coding.
const uint32_t num_orientations = (uint32_t)orientations_.size();
const uint32_t num_orientations = static_cast<uint32_t>(orientations_.size());
EncodeVarint(num_orientations, buffer);
bool last_orientation = true;
RAnsBitEncoder encoder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ bool MeshPredictionSchemeTexCoordsPortableDecoder<
predictor_.SetEntryToPointIdMap(entry_to_point_id_map);
this->transform().Initialize(num_components);

const int corner_map_size = (int)this->mesh_data().data_to_corner_map()->size();
const int corner_map_size = static_cast<int>(this->mesh_data().data_to_corner_map()->size());
for (int p = 0; p < corner_map_size; ++p) {
const CornerIndex corner_id = this->mesh_data().data_to_corner_map()->at(p);
if (!predictor_.template ComputePredictedValue<false>(corner_id, out_data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ bool MeshPredictionSchemeTexCoordsPortableEncoder<DataTypeT, TransformT,
this->transform().Initialize(in_data, size, num_components);
// We start processing from the end because this prediction uses data from
// previous entries that could be overwritten when an entry is processed.
for (int p = (int)(this->mesh_data().data_to_corner_map()->size() - 1); p >= 0;
for (int p = static_cast<int>(this->mesh_data().data_to_corner_map()->size() - 1); p >= 0;
--p) {
const CornerIndex corner_id = this->mesh_data().data_to_corner_map()->at(p);
predictor_.template ComputePredictedValue<true>(corner_id, in_data, p);
Expand Down
Loading

0 comments on commit c0c6ee1

Please sign in to comment.