本文整理汇总了C++中MultiTag::positions方法的典型用法代码示例。如果您正苦于以下问题:C++ MultiTag::positions方法的具体用法?C++ MultiTag::positions怎么用?C++ MultiTag::positions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MultiTag
的用法示例。
在下文中一共展示了MultiTag::positions方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testCreateRemove
void BaseTestMultiTag::testCreateRemove() {
std::vector<std::string> ids;
ndsize_t count = block.multiTagCount();
const char *names[5] = { "tag_a", "tag_b", "tag_c", "tag_d", "tag_e" };
for (int i = 0; i < 5; i++) {
std::string type = "Event";
MultiTag dt1 = block.createMultiTag(names[i], type, positions);
MultiTag dt2 = block.getMultiTag(dt1.id());
ids.push_back(dt1.id());
std::stringstream errmsg;
errmsg << "Error while accessing multiTag: dt1.id() = " << dt1.id()
<< " / dt2.id() = " << dt2.id();
CPPUNIT_ASSERT_MESSAGE(errmsg.str(), dt1.id().compare(dt2.id()) == 0);
}
std::stringstream errmsg2;
errmsg2 << "Error creating MultiTags. Counts do not match!";
CPPUNIT_ASSERT_MESSAGE(errmsg2.str(), block.multiTagCount() == (count+5));
CPPUNIT_ASSERT_THROW(block.createMultiTag(names[4], "test", positions), DuplicateName);
for (size_t i = 0; i < ids.size(); i++) {
block.deleteMultiTag(ids[i]);
}
std::stringstream errmsg1;
errmsg1 << "Error while removing multiTags!";
CPPUNIT_ASSERT_MESSAGE(errmsg1.str(), block.multiTagCount() == count);
DataArray a;
MultiTag mtag;
CPPUNIT_ASSERT_THROW(mtag = block.createMultiTag("test", "test", a), nix::UninitializedEntity);
mtag = block.createMultiTag("test", "test", positions);
mtag.extents(positions);
CPPUNIT_ASSERT_THROW(mtag.positions(a), UninitializedEntity);
CPPUNIT_ASSERT(mtag.extents().id() == positions.id());
CPPUNIT_ASSERT_NO_THROW(mtag.extents(a));
CPPUNIT_ASSERT(!mtag.extents());
}
示例2: retrieveData
DataView retrieveData(const MultiTag &tag, size_t position_index, size_t reference_index) {
DataArray positions = tag.positions();
DataArray extents = tag.extents();
vector<DataArray> refs = tag.references();
if (refs.size() == 0) { // Do I need this?
throw nix::OutOfBounds("There are no references in this tag!", 0);
}
if (position_index >= positions.dataExtent()[0] ||
(extents && position_index >= extents.dataExtent()[0])) {
throw nix::OutOfBounds("Index out of bounds of positions or extents!", 0);
}
if (!(reference_index < tag.referenceCount())) {
throw nix::OutOfBounds("Reference index out of bounds.", 0);
}
size_t dimension_count = refs[reference_index].dimensionCount();
if (positions.dataExtent().size() == 1 && dimension_count != 1) {
throw nix::IncompatibleDimensions("Number of dimensions in position or extent do not match dimensionality of data",
"util::retrieveData");
} else if (positions.dataExtent().size() > 1) {
if (positions.dataExtent()[1] > dimension_count ||
(extents && extents.dataExtent()[1] > dimension_count)) {
throw nix::IncompatibleDimensions("Number of dimensions in position or extent do not match dimensionality of data",
"util::retrieveData");
}
}
NDSize offset, count;
getOffsetAndCount(tag, refs[reference_index], position_index, offset, count);
if (!positionAndExtentInData(refs[reference_index], offset, count)) {
throw nix::OutOfBounds("References data slice out of the extent of the DataArray!", 0);
}
DataView io = DataView(refs[reference_index], count, offset);
return io;
}
示例3: getOffsetAndCount
void getOffsetAndCount(const MultiTag &tag, const DataArray &array, size_t index, NDSize &offsets, NDSize &counts) {
DataArray positions = tag.positions();
DataArray extents = tag.extents();
NDSize position_size, extent_size;
size_t dimension_count = array.dimensionCount();
if (positions) {
position_size = positions.dataExtent();
}
if (extents) {
extent_size = extents.dataExtent();
}
if (!positions || index >= position_size[0]) {
throw nix::OutOfBounds("Index out of bounds of positions!", 0);
}
if (extents && index >= extent_size[0]) {
throw nix::OutOfBounds("Index out of bounds of positions or extents!", 0);
}
if (position_size.size() == 1 && dimension_count != 1) {
throw nix::IncompatibleDimensions("Number of dimensions in positions does not match dimensionality of data",
"util::getOffsetAndCount");
}
if (position_size.size() > 1 && position_size[1] > dimension_count) {
throw nix::IncompatibleDimensions("Number of dimensions in positions does not match dimensionality of data",
"util::getOffsetAndCount");
}
if (extents && extent_size.size() > 1 && extent_size[1] > dimension_count) {
throw nix::IncompatibleDimensions("Number of dimensions in extents does not match dimensionality of data",
"util::getOffsetAndCount");
}
NDSize temp_offset = NDSize{static_cast<NDSize::value_type>(index), static_cast<NDSize::value_type>(0)};
NDSize temp_count{static_cast<NDSize::value_type>(1), static_cast<NDSize::value_type>(dimension_count)};
vector<double> offset;
positions.getData(offset, temp_count, temp_offset);
NDSize data_offset(dimension_count, static_cast<size_t>(0));
NDSize data_count(dimension_count, static_cast<size_t>(1));
vector<string> units = tag.units();
for (size_t i = 0; i < offset.size(); ++i) {
Dimension dimension = array.getDimension(i+1);
string unit = "none";
if (i <= units.size() && units.size() > 0) {
unit = units[i];
}
data_offset[i] = positionToIndex(offset[i], unit, dimension);
}
if (extents) {
vector<double> extent;
extents.getData(extent, temp_count, temp_offset);
for (size_t i = 0; i < extent.size(); ++i) {
Dimension dimension = array.getDimension(i+1);
string unit = "none";
if (i <= units.size() && units.size() > 0) {
unit = units[i];
}
ndsize_t c = positionToIndex(offset[i] + extent[i], unit, dimension) - data_offset[i];
data_count[i] = (c > 1) ? c : 1;
}
}
offsets = data_offset;
counts = data_count;
}