DriveWorks SDK Reference
3.5.78 Release
For Test and Development only

maps/docs/usecase8.md
Go to the documentation of this file.
1 # Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
2 
3 @page maps_usecase8 Content Slice and Updates
4 
5 @note SW Release Applicability: This tutorial is applicable to modules in **NVIDIA DRIVE Software** releases.
6 
7 As described in @ref maps_usecase2 the Core Layer data is contained directly by the Map object
8 returned as the result of a map request. Content Slice provides a complementary mechanism
9 to access data-intensive Content Layer data per application and driving domain requirements.
10 
11 Available Content Layers are obtained from the Map Provider interface.
12 
13 ```{.cpp}
14  dwStatus dwMapProvider_getContentLayers(dwMapsContentLayerBuffer* layers,
15  dwConstMapsProviderHandle_t providerHandle);
16 ```
17 
18 As mentioned in @ref maps_usecase2, desired Content Layers may be specified when launching a map
19 request, along with a geographic bounds or a planned route defined by WGS84 waypoints.
20 
21 ```{.cpp}
22  dwStatus dwMapProvider_requestMapForRoute(
23  dwMapsRequestToken* requestToken,
24  const dwMapsRoute* route,
25  const dwMapsContentLayerBuffer* layers,
26  dwMapProviderHandle_t providerHandle);
27 ```
28 
29 Completion of a map requests provides a data guarantee for the requested Content Layers, subject to
30 availability for the requested Map. Map requests shall not fail in general due to limited coverage
31 of requested Content Layers because we cannot guarantee full coverage for all layers, however
32 local views into a Content Layers with sparse coverage may appear "empty" to the application.
33 
34 This contract may change in future versions of the DriveWorks SDK, for example if applications
35 are found to require complete coverage of requested Content Layers for safety reasons. Consuming
36 code should not be harmed by this change if implemented, although more frequent map request
37 failures may be observed for map requests in regions with limited Content Layer coverage.
38 
39 The runtime mechanism for accessing Content Layers is called the Content Slice. This object is
40 responsible for asynchronous retrieval of "layer slices" of selected Content Layers to provide
41 local views into layer data for the client application.
42 
43 Initialization of the Content Slice requires a list of Content Layers and a LocalLayout "scope"
44 parameter defined as a maximum number of road segments per Local Layout. Those parameters are
45 used internally to allocate memory as needed for the requested layers.
46 
47 ```{.cpp}
48  dwStatus dwMapsContentSlice_initialize(
49  dwMapsContentSliceHandle_t* contentSliceHandle,
50  const dwMapsContentLayerBuffer* layers,
51  size_t maxSegmentsPerLayout,
52  dwMapProviderHandle_t providerHandle);
53 ```
54 
55 In the future we will add an explicit memory allocation cap to ContentSlice for improved control.
56 
57 A typical application of ContentSlice is to retrieve local views of point clouds, localization
58 images and other data-intensive content. Since these objects may not all be stored in memory for
59 the full map, they are loaded from disk on demand and therefore accessed by asynchronous APIs.
60 
61 The Content Slice object provides local view APIs to access the currently loaded content:
62 
63 ```{.cpp}
64  dwStatus dwMapsContentSlice_getImageLayerView(
65  dwConstMapsImageLayerViewHandle_t* imageLayerViewHandle,
66  dwConstMapsContentLayerHandle_t imageLayerHandle,
67  dwMapsContentSliceHandle_t contentSliceHandle);
68 
69  dwStatus dwMapsContentSlice_getPointCloudLayerView(
70  dwConstMapsPointCloudLayerViewHandle_t* pointCloudLayerViewHandle,
71  dwConstMapsContentLayerHandle_t pointCloudLayer,
72  dwMapsContentSliceHandle_t contentSliceHandle);
73 ```
74 
75 In order to load Content Layer data two objects are needed, Content Slice and Local Layout.
76 Here is a partial use case for initialiation of these objects:
77 
78 ```{.cpp}
79  // Create content slice object including all layers
80  dwMapsContentSliceHandle_t contentSliceHandle = nullptr;
81  dwMapsContentSlice_initialize(
82  &contentSliceHandle,
83  &layerBuffer,
84  MAX_ROAD_SEGMENTS,
85  providerHandle);
86 
87  dwMapsLocalLayoutHandle_t localLayoutHandle = DW_NULL_HANDLE
88  dwMapsLocalLayout_initialize(
89  &localLayoutHandle,
90  MAX_ROAD_SEGMENTS,
91  10); /* maxComponents */
92 ```
93 
94 There is requirement for asynchronous updates, to avoid blocking the calling thread which
95 in general may have real-time execution constraints. In addition it is required to use
96 a polling API instead of callbacks to simplify application-side threading concerns.
97 
98 This makes the full use for updating a Content Slice a bit complex:
99 
100 ```{.cpp}
101  std::vector<dwMapsRoadSegment> roadSegments(MAX_ROAD_SEGMENTS);
102 
103  dwMapsRoadSegmentBuffer roadSegmentBuffer = {0};
104  roadSegmentBuffer.buffer = roadSegments.data();
105  roadSegmentBuffer.maxSize = roadSegments.capacity();
106  roadSegmentBuffer.size = 0;
107 
108  dwMaps_getRoadSegments(
109  &roadSegmentBuffer,
110  layoutBounds, /* required bounds for Content Layers */
111  mapHandle);
112 
113  dwMapsLocalLayout_addRoadSegments(
114  roadSegmentBuffer.buffer,
115  roadSegmentBuffer.size,
116  localLayoutHandle);
117 
118  dwMapsLocalLayout_build(
119  &layoutOrigin,
120  localLayoutHandle);
121 
122  // Update loaded content asynchronously
123  dwMapsContentUpdateToken updateToken = 0;
124  dwMapsContentSlice_updateAsync(
125  &updateToken,
126  localLayoutHandle,
127  0,
128  contentSliceHandle);
129 
130  bool updateCompleted = false;
131 
132  // Wait for completion of content update
133  while (!updateCompleted)
134  {
135  std::this_thread::yield();
136 
137  /* At this point content is loading in the background
138  * It should not be available until dwMapsContentSlice_tryCompleteUpdate() succeeds.
139  * "Completion" of the update triggers a swtich all layer views to present updated content. */
140  status = dwMapsContentSlice_tryCompleteUpdate(
141  updateToken,
142  contentSliceHandle);
143 
144  if (status == DW_SUCCESS)
145  {
146  /* Now the application can access the updated content */
147  updateCompleted = true;
148  }
149  else (status = DW_NOT_READY)
150  {
151  /* This is OK, it means the update is still pending */
152  }
153  {
154  /* This is an error case */
155  }
156  }
157 ```