@@ -26,6 +26,11 @@ extern {
2626 minval : c_double , maxval : c_double , props : CellPtr ) -> c_int ;
2727}
2828
29+ /// Represents a sub-view of Window
30+ ///
31+ /// This struct is used in conjunction with [Window](./struct.Window.html) in multiview
32+ /// mode to render multiple targets to sub-regions of a given window.
33+ ///
2934#[ repr( C ) ]
3035pub struct Cell {
3136 pub row : i32 ,
@@ -34,6 +39,36 @@ pub struct Cell {
3439 pub cmap : ColorMap ,
3540}
3641
42+ /// Used to render [Array](./struct.Array.html) objects
43+ ///
44+ /// The renderings can be either plots, histograms or simply just image displays.
45+ /// A single window can also display multiple of the above renderings at the same time, which
46+ /// is known as multiview mode. An example of that is given below.
47+ ///
48+ /// # Examples
49+ ///
50+ /// ```
51+ /// let wnd = Window::new(1280, 720, String::from("Image Histogram")).unwrap();
52+ /// let img = match load_image("Path to image", true/*If color image, 'false' otherwise*/) {
53+ /// Ok(img) => img,
54+ /// Err(err) => panic!("Image loading failed with error code {}", err),
55+ /// };
56+ /// let hst = histogram(img, 256, 0, 255).unwrap();
57+ ///
58+ /// loop {
59+ /// wnd.grid(2, 1);
60+ ///
61+ /// wnd.set_view(0, 0);
62+ /// wnd.draw_image(img, Some("Input Image"));
63+ ///
64+ /// wnd.set_view(1, 0);
65+ /// wnd.draw_histogram(hst, 0.0, 255.0, Some("Input Image Histogram"));
66+ ///
67+ /// wnd.show();
68+ ///
69+ /// if wnd.is_closed().unwrap() == true { break; }
70+ /// }
71+ /// ```
3772#[ derive( Clone ) ]
3873pub struct Window {
3974 handle : u64 ,
@@ -42,6 +77,7 @@ pub struct Window {
4277 cmap : ColorMap ,
4378}
4479
80+ /// Used to create Window object from native(ArrayFire) resource handle
4581impl From < u64 > for Window {
4682 fn from ( t : u64 ) -> Window {
4783 Window { handle : t, row : -1 , col : -1 , cmap : ColorMap :: DEFAULT }
@@ -61,6 +97,7 @@ impl Drop for Window {
6197}
6298
6399impl Window {
100+ /// Creates new Window object
64101 #[ allow( unused_mut) ]
65102 pub fn new ( width : i32 , height : i32 , title : String ) -> Result < Window , AfError > {
66103 unsafe {
@@ -75,6 +112,7 @@ impl Window {
75112 }
76113 }
77114
115+ /// Set window starting position on the screen
78116 pub fn set_position ( & self , x : u32 , y : u32 ) -> Result < ( ) , AfError > {
79117 unsafe {
80118 let err_val = af_set_position ( self . handle as WndHandle , x as c_uint , y as c_uint ) ;
@@ -85,6 +123,7 @@ impl Window {
85123 }
86124 }
87125
126+ /// Set window title
88127 pub fn set_title ( & self , title : String ) -> Result < ( ) , AfError > {
89128 unsafe {
90129 let err_val = af_set_title ( self . handle as WndHandle ,
@@ -96,10 +135,13 @@ impl Window {
96135 }
97136 }
98137
138+ /// Set color map to be used for rendering image, it can take one of the values of enum
139+ /// [ColorMap](./enum.ColorMap.html)
99140 pub fn set_colormap ( & mut self , cmap : ColorMap ) {
100141 self . cmap = cmap;
101142 }
102143
144+ /// Returns true if the window close is triggered by the user
103145 pub fn is_closed ( & self ) -> Result < bool , AfError > {
104146 unsafe {
105147 let mut temp: i32 = 1 ;
@@ -111,6 +153,7 @@ impl Window {
111153 }
112154 }
113155
156+ /// Used to setup display layout in multiview mode
114157 pub fn grid ( & self , rows : i32 , cols : i32 ) -> Result < ( ) , AfError > {
115158 unsafe {
116159 let err_val = af_grid ( self . handle as WndHandle , rows as c_int , cols as c_int ) ;
@@ -121,6 +164,8 @@ impl Window {
121164 }
122165 }
123166
167+ /// Used in multiview mode to swap back buffer with front buffer to show the recently rendered
168+ /// frame
124169 pub fn show ( & mut self ) -> Result < ( ) , AfError > {
125170 unsafe {
126171 let err_val = af_show ( self . handle as WndHandle ) ;
@@ -133,11 +178,14 @@ impl Window {
133178 }
134179 }
135180
181+ /// Used in multiview mode to set the current sub-region to which the subsequence draw call
182+ /// renders to
136183 pub fn set_view ( & mut self , r : i32 , c : i32 ) {
137184 self . row = r;
138185 self . col = c;
139186 }
140187
188+ /// Render given Array as an image
141189 pub fn draw_image ( & self , input : & Array , title : Option < String > ) {
142190 let tstr = match title {
143191 Some ( s) => s,
@@ -154,6 +202,7 @@ impl Window {
154202 }
155203 }
156204
205+ /// Render given two Array's `x` and `y` as a 2d line plot
157206 pub fn draw_plot ( & self , x : & Array , y : & Array , title : Option < String > ) {
158207 let tstr = match title {
159208 Some ( s) => s,
@@ -172,6 +221,7 @@ impl Window {
172221 }
173222 }
174223
224+ /// Render given Array as a histogram
175225 pub fn draw_hist ( & self , hst : & Array , minval : f64 , maxval : f64 , title : Option < String > ) {
176226 let tstr = match title {
177227 Some ( s) => s,
0 commit comments