1 // =============================================================================
2 // PROJECT CHRONO - http://projectchrono.org
3 //
4 // Copyright (c) 2019 projectchrono.org
5 // All rights reserved.
6 //
7 // Use of this source code is governed by a BSD-style license that can be found
8 // in the LICENSE file at the top level of the distribution and at
9 // http://projectchrono.org/license-chrono.txt.
10 //
11 // =============================================================================
12 // Authors: Asher Elmquist
13 // =============================================================================
14 //
15 //
16 // =============================================================================
17 
18 #ifndef CHFILTERSAVE_H
19 #define CHFILTERSAVE_H
20 
21 #include "chrono_sensor/filters/ChFilter.h"
22 
23 #include <cuda.h>
24 
25 namespace chrono {
26 namespace sensor {
27 
28 // forward declaration
29 class ChSensor;
30 
31 /// @addtogroup sensor_filters
32 /// @{
33 
34 /// A filter that, when applied to a sensor, saves the data as an image.
35 class CH_SENSOR_API ChFilterSave : public ChFilter {
36   public:
37     /// Class constructor
38     /// @param data_path The path to save the data
39     /// @param name the name of the filter
40     ChFilterSave(std::string data_path = "", std::string name = "ChFilterSave");
41 
42     /// Class destructor
~ChFilterSave()43     virtual ~ChFilterSave() {}
44 
45     /// Apply function. Saves image data.
46     virtual void Apply();
47 
48     /// Initializes all data needed by the filter access apply function.
49     /// @param pSensor A pointer to the sensor on which the filter is attached.
50     /// @param bufferInOut A buffer that is passed into the filter.
51     virtual void Initialize(std::shared_ptr<ChSensor> pSensor, std::shared_ptr<SensorBuffer>& bufferInOut);
52 
53   private:
54     std::string m_path;               ///< path to where data should be saved
55     unsigned int m_frame_number = 0;  ///< frame counter to prevent overwriting data
56 
57     std::shared_ptr<SensorDeviceRGBA8Buffer> m_rgba8_in;  ///< input buffer for rgba8 image
58     std::shared_ptr<SensorHostRGBA8Buffer> m_host_rgba8;  ///< host buffer for rgba8 image
59 
60     std::shared_ptr<SensorDeviceR8Buffer> m_r8_in;  ///< input buffer for r8 image
61     std::shared_ptr<SensorHostR8Buffer> m_host_r8;  ///< host buffer for r8 image
62 
63     std::shared_ptr<SensorHostSemanticBuffer> m_semantic_in;    ///< input buffer for semantic image
64     std::shared_ptr<SensorHostSemanticBuffer> m_host_semantic;  ///< host buffer for semantic image
65 
66     CUstream m_cuda_stream;  ///< reference to the cuda stream
67 };
68 
69 /// @}
70 
71 }  // namespace sensor
72 }  // namespace chrono
73 
74 #endif
75