20#include "nlohmann/json.hpp" 
   27#include <QtCore/QBuffer> 
   37    const double west = region[0].get<
double>() * 180 / M_PI;
 
   38    const double south = region[1].get<
double>() * 180 / M_PI;
 
   39    const double east = region[2].get<
double>() * 180 / M_PI;
 
   40    const double north = region[3].get<
double>() * 180 / M_PI;
 
   41    double minHeight = region[4].get<
double>();
 
   42    double maxHeight = region[5].get<
double>();
 
   44    return QgsBox3D( west, south, minHeight, east, north, maxHeight );
 
   46  catch ( nlohmann::json::exception & )
 
 
   54  if ( region.size() != 6 )
 
 
   62  if ( box.size() != 12 )
 
   68    for ( 
int i = 0; i < 3; ++i )
 
   70      res.mCenter[i] = box[i].get<
double>();
 
   72    for ( 
int i = 0; i < 9; ++i )
 
   74      res.mHalfAxes[i] = box[i + 3].get<
double>();
 
   78  catch ( nlohmann::json::exception & )
 
 
   86  if ( box.size() != 12 )
 
 
   94  if ( sphere.size() != 4 )
 
   99    const double centerX = sphere[0].get<
double>();
 
  100    const double centerY = sphere[1].get<
double>();
 
  101    const double centerZ = sphere[2].get<
double>();
 
  102    const double radius = sphere[3].get<
double>();
 
  103    return QgsSphere( centerX, centerY, centerZ, radius );
 
  105  catch ( nlohmann::json::exception & )
 
 
  113  if ( sphere.size() != 4 )
 
 
  126    const double uniformScale = std::max(
 
  141    return QgsSphere( center.
x(), center.
y(), center.
z(), sphere.
radius() * uniformScale );
 
 
  150    unsigned char magic[4];
 
  153    quint32 featureTableJsonByteLength;
 
  154    quint32 featureTableBinaryByteLength;
 
  155    quint32 batchTableJsonByteLength;
 
  156    quint32 batchTableBinaryByteLength;
 
  160  if ( tileContent.size() < 
static_cast<int>( 
sizeof( b3dmHeader ) ) )
 
  164  memcpy( &hdr, tileContent.constData(), 
sizeof( b3dmHeader ) );
 
  166  const QString featureTableJson( tileContent.mid( 
sizeof( b3dmHeader ), hdr.featureTableJsonByteLength ) );
 
  167  if ( !featureTableJson.isEmpty() )
 
  171      const json featureTable = json::parse( featureTableJson.toStdString() );
 
  172      if ( featureTable.contains( 
"RTC_CENTER" ) )
 
  174        const auto &rtcCenterJson = featureTable[ 
"RTC_CENTER" ];
 
  175        if ( rtcCenterJson.is_array() && rtcCenterJson.size() == 3 )
 
  183          QgsDebugError( QStringLiteral( 
"Invalid RTC_CENTER value" ) );
 
  187    catch ( json::parse_error &ex )
 
  189      QgsDebugError( QStringLiteral( 
"Error parsing feature table JSON: %1" ).arg( ex.what() ) );
 
  193  res.
gltf = tileContent.mid( 
sizeof( b3dmHeader ) +
 
  194                              hdr.featureTableJsonByteLength + hdr.featureTableBinaryByteLength +
 
  195                              hdr.batchTableJsonByteLength + hdr.batchTableBinaryByteLength );
 
 
  202  if ( tileContent.startsWith( QByteArray( 
"b3dm" ) ) )
 
  209  else if ( tileContent.startsWith( QByteArray( 
"glTF" ) ) )
 
  211    res.
gltf = tileContent;
 
 
A 3-dimensional box composed of x, y, z coordinates.
 
static QgsSphere parseSphere(const json &sphere)
Parses a sphere object from a Cesium JSON document.
 
static B3DMContents extractGltfFromB3dm(const QByteArray &tileContent)
Extracts GLTF binary data and other contents from the legacy b3dm (Batched 3D Model) tile format.
 
static QgsOrientedBox3D parseBox(const json &box)
Parses a box object from a Cesium JSON document to an oriented bounding box.
 
static QgsBox3D parseRegion(const json ®ion)
Parses a region object from a Cesium JSON object to a 3D box.
 
static QgsSphere transformSphere(const QgsSphere &sphere, const QgsMatrix4x4 &transform)
Applies a transform to a sphere.
 
static TileContents extractGltfFromTileContent(const QByteArray &tileContent)
Parses tile content.
 
static json jsonFromVariant(const QVariant &v)
Converts a QVariant v to a json object.
 
A simple 4x4 matrix implementation useful for transformation in 3D space.
 
bool isIdentity() const
Returns whether this matrix is an identity matrix.
 
QgsVector3D map(const QgsVector3D &vector) const
Matrix-vector multiplication (vector is converted to homogeneous coordinates [X,Y,...
 
const double * constData() const
Returns pointer to the matrix data (stored in column-major order)
 
Represents a oriented (rotated) box in 3 dimensions.
 
A spherical geometry object.
 
QgsVector3D centerVector() const
Returns the vector to the center of the sphere.
 
double radius() const
Returns the radius of the sphere.
 
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
 
double y() const
Returns Y coordinate.
 
double z() const
Returns Z coordinate.
 
void setZ(double z)
Sets Z coordinate.
 
double x() const
Returns X coordinate.
 
void setX(double x)
Sets X coordinate.
 
void setY(double y)
Sets Y coordinate.
 
#define QgsDebugError(str)
 
Encapsulates the contents of a B3DM file.
 
QByteArray gltf
GLTF binary content.
 
QgsVector3D rtcCenter
Optional RTC center.
 
Encapsulates the contents of a 3D tile.
 
QgsVector3D rtcCenter
Center position of relative-to-center coordinates (when used)
 
QByteArray gltf
GLTF binary content.