Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collada and Assimp test for default animation names #428

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)
#============================================================================
# Initialize the project
#============================================================================
project(gz-common5 VERSION 5.1.0)
project(gz-common5 VERSION 5.2.2)
set(GZ_COMMON_VER ${PROJECT_VERSION_MAJOR})

#============================================================================
Expand Down Expand Up @@ -127,7 +127,6 @@ gz_find_package(AVUTIL REQUIRED_BY av PRETTY libavutil)
# Find assimp
gz_find_package(GzAssimp REQUIRED_BY graphics PRETTY assimp)


message(STATUS "-------------------------------------------\n")


Expand All @@ -138,7 +137,7 @@ configure_file("${PROJECT_SOURCE_DIR}/cppcheck.suppress.in"
${PROJECT_BINARY_DIR}/cppcheck.suppress)

gz_configure_build(QUIT_IF_BUILD_ERRORS
COMPONENTS av events geospatial graphics profiler testing)
COMPONENTS av events geospatial graphics io profiler testing)

#============================================================================
# Create package information
Expand Down
22 changes: 22 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
## Gazebo Common 5.x

## Gazebo Common 5.2.2 (2022-10-26)

1. [Backport] Avoid Io.hh header name clash (#471)
* [Pull request #472](https://github.com/gazebosim/gz-common/pull/472)

## Gazebo Common 5.2.1 (2022-10-19)

1. Fix arm builds and tests
* [Pull request #462](https://github.com/gazebosim/gz-common/pull/462)
* [Pull request #463](https://github.com/gazebosim/gz-common/pull/463)

## Gazebo Common 5.2.0 (2022-10-18)

1. Add CSV data parsing
* [Pull request #402](https://github.com/gazebosim/gz-common/pull/402)

1. Skip CSV header when reading DataFrame.
* [Pull request #435](https://github.com/gazebosim/gz-common/pull/435)

1. Adds an API to retrieve keys.
* [Pull request #446](https://github.com/gazebosim/gz-common/pull/446)

## Gazebo Common 5.1.0 (2022-10-13)

1. 4 ➡️ 5
Expand Down
17 changes: 17 additions & 0 deletions graphics/src/AssimpLoader_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -738,3 +738,20 @@ TEST_F(AssimpLoader, CheckNonRootDisplacement)
auto xDisplacement = skelAnim->XDisplacement();
ASSERT_TRUE(xDisplacement);
}

/////////////////////////////////////////////////
// Load animation without a name
TEST_F(AssimpLoader, NoAnimName)
{
common::AssimpLoader loader;

std::string meshFilename =
common::testing::TestFile("data", "box_with_no_animation_name.dae");

common::Mesh *mesh = loader.Load(meshFilename);
common::SkeletonPtr skeleton = mesh->MeshSkeleton();
ASSERT_EQ(1u, skeleton->AnimationCount());
common::SkeletonAnimation *anim = skeleton->Animation(0);
auto animName = anim->Name();
EXPECT_EQ(animName, "animation1");
}
17 changes: 17 additions & 0 deletions graphics/src/ColladaLoader_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -489,3 +489,20 @@ TEST_F(ColladaLoader, LoadCylinderAnimatedFrom3dsMax)
EXPECT_EQ(1u, anim->NodeCount());
EXPECT_TRUE(anim->HasNode("Bone02"));
}

/////////////////////////////////////////////////
// Load animation without a name
TEST_F(ColladaLoader, NoAnimName)
{
common::ColladaLoader loader;

std::string meshFilename =
common::testing::TestFile("data", "box_with_no_animation_name.dae");

common::Mesh *mesh = loader.Load(meshFilename);
common::SkeletonPtr skeleton = mesh->MeshSkeleton();
ASSERT_EQ(1u, skeleton->AnimationCount());
common::SkeletonAnimation *anim = skeleton->Animation(0);
auto animName = anim->Name();
EXPECT_EQ(animName, "animation1");
}
76 changes: 76 additions & 0 deletions io/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
load(
"//gz_bazel:build_defs.bzl",
"GZ_ROOT",
"GZ_VISIBILITY",
"generate_include_header",
"gz_export_header",
)

package(
default_visibility = GZ_VISIBILITY,
features = [
"-parse_headers",
"-layering_check",
],
)

public_headers_no_gen = glob([
"include/gz/common/*.hh",
])

sources = glob(
["src/*.cc"],
exclude = ["src/*_TEST.cc"],
)

test_sources = glob(["src/*_TEST.cc"])

gz_export_header(
name = "include/gz/common/io/Export.hh",
export_base = "GZ_COMMON_IO",
lib_name = "gz-common-io",
visibility = ["//visibility:private"],
)

generate_include_header(
name = "iohh_genrule",
out = "include/gz/common/io.hh",
hdrs = public_headers_no_gen + [
"include/gz/common/io/Export.hh",
],
)

public_headers = public_headers_no_gen + [
"include/gz/common/io/Export.hh",
"include/gz/common/io.hh",
]

cc_library(
name = "io",
srcs = sources,
hdrs = public_headers,
includes = ["include"],
deps = [
GZ_ROOT + "gz_common",
GZ_ROOT + "gz_math",
],
)

cc_binary(
name = "libgz-common5-io.so",
includes = ["include"],
linkopts = ["-Wl,-soname,libgz-common5-io.so"],
linkshared = True,
deps = [":events"],
)

[cc_test(
name = src.replace("/", "_").replace(".cc", "").replace("src_", ""),
srcs = [src],
deps = [
":io",
GZ_ROOT + "gz_common/test:test_utils",
"@gtest",
"@gtest//:gtest_main",
],
) for src in test_sources]
1 change: 1 addition & 0 deletions io/include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(gz)
1 change: 1 addition & 0 deletions io/include/gz/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(common)
1 change: 1 addition & 0 deletions io/include/gz/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gz_install_all_headers(COMPONENT io)
177 changes: 177 additions & 0 deletions io/include/gz/common/CSVStreams.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
/*
* Copyright (C) 2022 Open Source Robotics Foundation
*
* 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.
*
*/
#ifndef GZ_COMMON_CSVSTREAMS_HH_
#define GZ_COMMON_CSVSTREAMS_HH_

#include <istream>
#include <string>
#include <vector>

#include <gz/common/io/Export.hh>

#include <gz/utils/ImplPtr.hh>

namespace gz
{
namespace common
{
/// \brief A CSV specification.
struct GZ_COMMON_IO_VISIBLE CSVDialect
{
/// Field delimiter character.
char delimiter;

/// Row termination character.
char terminator;

/// Field quoting character.
char quote;

/// CSV dialect as expected by Unix tools.
static const CSVDialect Unix;
};

/// \brief Check CSV dialects for equality.
/// \param[in] _lhs Left-hand side CSV dialect.
/// \param[in] _rhs Right-hand side CSV dialect.
/// \return true if CSV dialects are equal, false otherwise.
bool GZ_COMMON_IO_VISIBLE operator==(const CSVDialect &_lhs,
const CSVDialect &_rhs);

/// \brief A token in CSV data.
///
/// Lexical specifications are typically dictated by a CSV dialect.
struct CSVToken
{
/// Token type.
enum {
TEXT = 0, ///< A pure text token (e.g. a letter).
QUOTE, ///< A field quoting token (e.g. a double quote).
DELIMITER, ///< A field delimiter token (e.g. a comma).
TERMINATOR ///< A row termination token (e.g. a newline).
} type;

/// Token character.
char character;
};

/// \brief Extract a single token from an input stream of CSV data.
///
/// If tokenization fails, the CSV data stream ``failbit`` will be set.
///
/// \param[in] _stream A stream of CSV data to tokenize.
/// \param[out] _token Output CSV token to extract into.
/// \param[in] _dialect CSV data dialect. Defaults to the Unix dialect.
/// \return same CSV data stream.
GZ_COMMON_IO_VISIBLE std::istream &ExtractCSVToken(
std::istream &_stream, CSVToken &_token,
const CSVDialect &_dialect = CSVDialect::Unix);

/// \brief Parse a single row from an input stream of CSV data.
///
/// If parsing fails, the CSV data stream ``failbit`` will be set.
///
/// \param[in] _stream CSV data stream to parse.
/// \param[out] _row Output CSV row to parse into.
/// \param[in] _dialect CSV data dialect. Defaults to the Unix dialect.
/// \returns same CSV data stream.
GZ_COMMON_IO_VISIBLE std::istream &ParseCSVRow(
std::istream &_stream, std::vector<std::string> &_row,
const CSVDialect &_dialect = CSVDialect::Unix);

/// \brief A single-pass row iterator on an input stream of CSV data.
///
/// Similar to std::istream_iterator, this iterator parses a stream of
/// CSV data, one row at a time. \see `ParseCSVRow`.
class GZ_COMMON_IO_VISIBLE CSVIStreamIterator
{
public: using iterator_category = std::input_iterator_tag;
public: using value_type = std::vector<std::string>;
public: using difference_type = std::ptrdiff_t;
public: using pointer = const value_type*;
public: using reference = const value_type&;

/// \brief Construct an end-of-stream iterator.
public: CSVIStreamIterator();

/// \brief Construct an iterator over `_stream`.
///
/// The first row will be read from the underlying stream to
/// initialize the iterator. If there are parsing errors while
/// reading, the underlying stream ``failbit`` will be set.
///
/// \param[in] _stream A stream of CSV data to iterate.
/// \param[in] _dialect CSV data dialect. Defaults to the Unix dialect.
public: explicit CSVIStreamIterator(
std::istream &_stream,
const CSVDialect &_dialect = CSVDialect::Unix);

/// \brief Read the next row from the underlying stream.
///
/// If the read fails, the iterator becomes an end-of-stream iterator.
/// If there are parsing errors while reading, the underlying stream
/// ``failbit`` will be set. If the iterator already is an end-of-stream
/// iterator, behavior is undefined.
///
/// \return A reference to the iterator once modified.
public: CSVIStreamIterator &operator++();

/// \brief Read the next row from the underlying stream.
///
/// If the read fails, the iterator becomes an end-of-stream iterator.
/// If there are parsing errors while reading, the underlying stream
/// ``failbit`` will be set. If the iterator already is an end-of-stream
/// iterator, behavior is undefined.
///
/// \return A copy of the iterator before modification. Note that,
/// while an iterator copy retains its state, the underlying stream
/// may still be advanced.
public: CSVIStreamIterator operator++(int);

/// \brief Check for iterator equality.
/// \param[in] _other Iterator to compare with.
/// \return true if both iterators are end-of-stream iterators
/// or if both iterator wrap the same stream and use the same dialect,
/// false otherwise.
public: bool operator==(const CSVIStreamIterator &_other) const;

/// \brief Check for iterator inequality.
/// \param[in] _other Iterator to compare with.
/// \return true if both iterators are not equal, false otherwise.
public: bool operator!=(const CSVIStreamIterator &_other) const;

/// \brief Access current row.
///
/// Behavior is undefined if the iterator is an end-of-stream iterator.
///
/// \return reference to the current row.
public: reference operator*() const;

/// \brief Access current row.
///
/// Behavior is undefined if the iterator is an end-of-stream iterator.
///
/// \return pointer to the current row.
public: pointer operator->() const;

/// \brief Pointer to private data.
private: GZ_UTILS_IMPL_PTR(dataPtr)
};
}
}

#endif
Loading