ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
cloudViewer::io::rpc::messages::Array Struct Reference

#include <Messages.h>

Collaboration diagram for cloudViewer::io::rpc::messages::Array:

Public Member Functions

template<class T >
const T * Ptr () const
 
bool CheckRank (const std::vector< int > &expected_ranks, std::string &errstr) const
 
bool CheckRank (const std::vector< int > &expected_ranks) const
 
bool CheckShape (const std::vector< int64_t > &expected_shape, std::string &errstr) const
 
bool CheckShape (const std::vector< int64_t > &expected_shape) const
 
bool CheckNonEmpty (std::string &errstr) const
 
bool CheckNonEmpty () const
 
bool CheckType (const std::vector< std::string > &expected_types, std::string &errstr) const
 
bool CheckType (const std::vector< std::string > &expected_types) const
 
 MSGPACK_DEFINE_MAP (type, shape, data)
 

Static Public Member Functions

static std::string MsgId ()
 
template<class T >
static Array FromPtr (const T *const ptr, const std::vector< int64_t > &shape)
 
static Array FromTensor (const core::Tensor &tensor)
 

Public Attributes

core::Tensor tensor_
 
std::string type
 
std::vector< int64_t > shape
 
msgpack::type::raw_ref data
 

Detailed Description

Array structure inspired by msgpack_numpy but not directly compatible because they use bin-type for the map keys and we must use string. This structure does not have ownership of the data.

The following code can be used in python to create a compatible dict

def numpy_to_Array(arr): if isinstance(arr, np.ndarray): return {'type': arr.dtype.str, 'shape': arr.shape, 'data': arr.tobytes()} raise Exception('object is not a numpy array')

This codes converts the dict back to numpy.ndarray

def Array_to_numpy(dic): return np.frombuffer(dic['data'], dtype=np.dtype(dic['type'])).reshape(dic['shape'])

Definition at line 104 of file Messages.h.

Member Function Documentation

◆ CheckNonEmpty() [1/2]

bool cloudViewer::io::rpc::messages::Array::CheckNonEmpty ( ) const
inline

Definition at line 225 of file Messages.h.

◆ CheckNonEmpty() [2/2]

bool cloudViewer::io::rpc::messages::Array::CheckNonEmpty ( std::string &  errstr) const
inline

Checks for a non empty array. Returns false if the array is empty and appends an error description to errstr.

Definition at line 212 of file Messages.h.

References shape, and patch::to_string().

Referenced by cloudViewer::io::rpc::messages::MeshData::CheckFaces(), cloudViewer::io::rpc::messages::MeshData::CheckVertices(), cloudViewer::io::rpc::MeshDataToGeometry(), and cloudViewer::visualization::MessageProcessor::ProcessMessage().

◆ CheckRank() [1/2]

bool cloudViewer::io::rpc::messages::Array::CheckRank ( const std::vector< int > &  expected_ranks) const
inline

Definition at line 168 of file Messages.h.

References CheckRank().

◆ CheckRank() [2/2]

bool cloudViewer::io::rpc::messages::Array::CheckRank ( const std::vector< int > &  expected_ranks,
std::string &  errstr 
) const
inline

Checks the rank of the shape. Returns false on mismatch and appends an error description to errstr.

Definition at line 152 of file Messages.h.

References shape, and patch::to_string().

Referenced by cloudViewer::io::rpc::messages::MeshData::CheckFaces(), CheckRank(), and CheckShape().

◆ CheckShape() [1/2]

bool cloudViewer::io::rpc::messages::Array::CheckShape ( const std::vector< int64_t > &  expected_shape) const
inline

Definition at line 204 of file Messages.h.

References CheckShape().

◆ CheckShape() [2/2]

bool cloudViewer::io::rpc::messages::Array::CheckShape ( const std::vector< int64_t > &  expected_shape,
std::string &  errstr 
) const
inline

Checks the shape against the expected shape. Use -1 in the expected shape to allow arbitrary values. Returns false on mismatch and appends an error description to errstr.

Definition at line 176 of file Messages.h.

References CheckRank(), shape, and patch::to_string().

Referenced by CheckShape(), cloudViewer::io::rpc::messages::MeshData::CheckVertices(), and cloudViewer::io::rpc::MeshDataToGeometry().

◆ CheckType() [1/2]

bool cloudViewer::io::rpc::messages::Array::CheckType ( const std::vector< std::string > &  expected_types) const
inline

Definition at line 245 of file Messages.h.

References CheckType().

◆ CheckType() [2/2]

bool cloudViewer::io::rpc::messages::Array::CheckType ( const std::vector< std::string > &  expected_types,
std::string &  errstr 
) const
inline

Checks the data type of the array. Returns false if the type is not in the list of expected types and appends an error description to errstr.

Definition at line 233 of file Messages.h.

References type.

Referenced by cloudViewer::io::rpc::messages::MeshData::CheckFaces(), CheckType(), and cloudViewer::visualization::MessageProcessor::ProcessMessage().

◆ FromPtr()

template<class T >
static Array cloudViewer::io::rpc::messages::Array::FromPtr ( const T *const  ptr,
const std::vector< int64_t > &  shape 
)
inlinestatic

Creates an Array from a pointer. The caller is responsible for keeping the pointer valid during the lifetime of the Array object.

Definition at line 110 of file Messages.h.

References data, shape, and type.

◆ FromTensor()

static Array cloudViewer::io::rpc::messages::Array::FromTensor ( const core::Tensor tensor)
inlinestatic

Creates an Array from a Tensor. This will copy the tensor to contiguous CPU memory if necessary and the returned array will keep a reference.

Definition at line 125 of file Messages.h.

References cloudViewer::core::Tensor::Contiguous(), DISPATCH_DTYPE_TO_TEMPLATE, and cloudViewer::core::Tensor::To().

◆ MsgId()

static std::string cloudViewer::io::rpc::messages::Array::MsgId ( )
inlinestatic

Definition at line 105 of file Messages.h.

◆ MSGPACK_DEFINE_MAP()

cloudViewer::io::rpc::messages::Array::MSGPACK_DEFINE_MAP ( type  ,
shape  ,
data   
)

◆ Ptr()

template<class T >
const T* cloudViewer::io::rpc::messages::Array::Ptr ( ) const
inline

Definition at line 146 of file Messages.h.

References data.

Referenced by cloudViewer::visualization::MessageProcessor::ProcessMessage().

Member Data Documentation

◆ data

msgpack::type::raw_ref cloudViewer::io::rpc::messages::Array::data

Definition at line 143 of file Messages.h.

Referenced by cloudViewer::io::rpc::ArrayToTensor(), FromPtr(), and Ptr().

◆ shape

◆ tensor_

core::Tensor cloudViewer::io::rpc::messages::Array::tensor_

Definition at line 139 of file Messages.h.

◆ type

std::string cloudViewer::io::rpc::messages::Array::type

The documentation for this struct was generated from the following file: