Skip to content

Commit 8c302eb

Browse files
committed
refactor: remove SIMG-based image output
- drop the SIMG/SIMG_Frame wrappers and bundled stb image headers - switch SGLFW and CSGOptiX snapshot output from jpg/png to raw npy buffers - remove SIMG-dependent tests and the qudarap image rotation test
1 parent 5418d71 commit 8c302eb

22 files changed

Lines changed: 104 additions & 10653 deletions

CSGOptiX/CSGOptiX.cc

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,7 @@ const char* CSGOptiX::getDefaultSnapPath() const
11961196
assert( foundry );
11971197
const char* cfbase = foundry->getOriginCFBase();
11981198
assert( cfbase );
1199-
const char* path = SPath::Resolve(cfbase, "CSGOptiX/snap.jpg" , FILEPATH );
1199+
const char* path = SPath::Resolve(cfbase, "CSGOptiX/snap.npy", FILEPATH);
12001200
return path ;
12011201
}
12021202

@@ -1297,11 +1297,11 @@ void CSGOptiX::render_save_(const char* stem_, bool inverted)
12971297
const char* stem = stem_ ? stem_ : getRenderStemDefault() ; // without ext
12981298

12991299
bool unique = true ;
1300-
const char* outpath = SEventConfig::OutPath(stem, -1, ".jpg", unique );
1300+
const char* outpath = SEventConfig::OutPath(stem, -1, ".npy", unique);
13011301

13021302
LOG(LEVEL)
1303-
<< SEventConfig::DescOutPath(stem, -1, ".jpg", unique );
1304-
;
1303+
<< SEventConfig::DescOutPath(stem, -1, ".npy", unique);
1304+
;
13051305

13061306
std::string u_outdir ;
13071307
std::string u_stem ;
@@ -1324,15 +1324,13 @@ void CSGOptiX::render_save_(const char* stem_, bool inverted)
13241324

13251325
LOG(info) << outpath << " : " << AnnotationTime(kernel_dt, extra) ;
13261326

1327-
snap(outpath, inverted );
1328-
1327+
snap(outpath, inverted);
13291328

13301329
sglm->save( u_outdir.c_str(), u_stem.c_str() );
13311330
}
13321331

1333-
13341332
/**
1335-
CSGOptiX::snap : Download frame pixels and write to file as jpg.
1333+
CSGOptiX::snap : Download frame pixels and write to file as NPY.
13361334
------------------------------------------------------------------
13371335
13381336
WIP: contrast this with SGLFW::snap_local and consider if more consolidation is possible
@@ -1346,7 +1344,7 @@ CSGOptiX::snap
13461344
13471345
**/
13481346

1349-
void CSGOptiX::snap(const char* path_, bool inverted )
1347+
void CSGOptiX::snap(const char* path_, bool inverted)
13501348
{
13511349
const char* path = path_ ? SPath::Resolve(path_, FILEPATH ) : getDefaultSnapPath() ;
13521350
LOG(LEVEL) << " path " << path ;
@@ -1387,13 +1385,14 @@ int CSGOptiX::render_flightpath() // for making mp4 movies
13871385
return 1 ;
13881386
}
13891387

1390-
void CSGOptiX::saveMeta(const char* jpg_path) const
1388+
void CSGOptiX::saveMeta(const char* path) const
13911389
{
1392-
const char* json_path = SStr::ReplaceEnd(jpg_path, ".jpg", ".json");
1390+
const char* json_path = SStr::ReplaceEnd(path, ".npy", ".json");
13931391
LOG(LEVEL) << "[ json_path " << json_path ;
13941392

13951393
nlohmann::json& js = meta->js ;
1396-
js["jpg"] = jpg_path ;
1394+
js["path"] = path;
1395+
js["npy"] = path;
13971396
js["emm"] = SGeoConfig::EnabledMergedMesh() ;
13981397

13991398
if(foundry->hasMeta())

CSGOptiX/CSGOptiX.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,14 @@ struct CSGOPTIX_API CSGOptiX : public SSimulator
177177
const CSGFoundry* getFoundry() const ;
178178
static std::string AnnotationTime( double dt, const char* extra=nullptr );
179179
const char* getDefaultSnapPath() const ;
180-
void snap(const char* path, bool inverted ); // part of SRenderer protocol base
181-
180+
void snap(const char* path, bool inverted); // part of SRenderer protocol base
182181

183182
#ifdef WITH_FRAME_PHOTON
184183
void writeFramePhoton(const char* dir, const char* name);
185184
#endif
186185
int render_flightpath();
187186

188-
void saveMeta(const char* jpg_path) const ;
187+
void saveMeta(const char* path) const;
189188

190189
static constexpr const char* CTX_LOGNAME = "CSGOptiX__Ctx.log" ;
191190
void write_Ctx_log(const char* dir=nullptr) const ;

CSGOptiX/Frame.cc

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,14 @@
77

88
#include "SFrameConfig.hh"
99
#include "SComp.h"
10-
#include "SStr.hh"
1110
#include "SPath.hh"
1211
#include "SLOG.hh"
1312
#include "NP.hh"
1413
#include "Frame.h"
1514

16-
#define SIMG_IMPLEMENTATION 1
17-
#include "SIMG.h"
18-
1915

2016
const plog::Severity Frame::LEVEL = SLOG::EnvLevel("Frame", "DEBUG" );
2117

22-
unsigned Frame::getNumPixels() const
23-
{
24-
return num_pixels ;
25-
}
26-
2718
/**
2819
Frame::Frame
2920
--------------
@@ -58,8 +49,6 @@ Frame::Frame(int width_, int height_, int depth_, uchar4* d_pixel_, float4* d_is
5849
height(height_),
5950
depth(depth_),
6051
channels(4),
61-
jpg_quality(SStr::GetEValue<int>("QUALITY", 50)),
62-
img(new SIMG(width, height, channels, nullptr )),
6352
num_pixels(width*height),
6453
d_pixel(d_pixel_ == nullptr ? DeviceAlloc<uchar4>(num_pixels, mask & SCOMP_PIXEL ) : d_pixel_ ),
6554
d_isect(d_isect_ == nullptr ? DeviceAlloc<float4>(num_pixels, mask & SCOMP_ISECT ) : d_isect_ ),
@@ -107,10 +96,8 @@ void Frame::download_(bool flip_vertical)
10796
if(d_fphoton) QU::Download<quad4>(photon, d_fphoton, num_pixels );
10897
#endif
10998

110-
if(d_pixel)
111-
{
112-
img->setData( getPixelData(), flip_vertical );
113-
}
99+
if (d_pixel && flip_vertical)
100+
flipPixelVertical();
114101
}
115102

116103
void Frame::download()
@@ -122,41 +109,24 @@ void Frame::download_inverted()
122109
download_(false);
123110
}
124111

125-
126-
127-
unsigned char* Frame::getPixelData() const { return d_pixel ? (unsigned char*)pixel.data() : nullptr ; }
128112
float* Frame::getIntersectData() const { return d_isect ? (float*)isect.data() : nullptr ; }
129113
#ifdef WITH_FRAME_PHOTON
130114
float* Frame::getFPhotonData() const { return d_fphoton ? (float*)fphoton.data() : nullptr ; }
131115
#endif
132116

133-
void Frame::write(const char* outdir_, int quality) const
134-
{
135-
const char* outdir = SPath::Resolve(outdir_, DIRPATH);
136-
writePNG(outdir, "f_pixels.png");
137-
writeJPG(outdir, "f_pixels.jpg", quality);
138-
writeIsect(outdir, "f_isect.npy" ); // formerly posi.npy
139-
#ifdef WITH_FRAME_PHOTON
140-
writeFPhoton(outdir, "f_photon.npy" );
141-
#endif
142-
}
143-
144-
void Frame::writePNG(const char* dir, const char* name) const
145-
{
146-
img->writePNG(dir, name);
147-
}
148-
void Frame::writePNG(const char* path) const
117+
void Frame::flipPixelVertical()
149118
{
150-
img->writePNG(path);
119+
for (int y = 0; y < height / 2; y++)
120+
for (int x = 0; x < width; x++)
121+
{
122+
std::swap(pixel[y * width + x], pixel[(height - 1 - y) * width + x]);
123+
}
151124
}
152125

153-
void Frame::writeJPG(const char* dir, const char* name, int quality) const
154-
{
155-
img->writeJPG(dir, name, quality > 0 ? quality : jpg_quality );
156-
}
157-
void Frame::writeJPG(const char* path, int quality) const
126+
void Frame::writePixels(const char* path) const
158127
{
159-
img->writeJPG(path, quality > 0 ? quality : jpg_quality );
128+
if (d_pixel)
129+
NP::Write(path, (unsigned char*)pixel.data(), height, width, channels);
160130
}
161131

162132

@@ -176,12 +146,11 @@ void Frame::writeFPhoton( const char* dir, const char* name) const
176146

177147
void Frame::snap( const char* path )
178148
{
179-
LOG(LEVEL) << "[" ;
180-
181-
LOG(LEVEL) << "[ writeJPG " ;
182-
writeJPG( path );
183-
LOG(LEVEL) << "] writeJPG " ;
149+
LOG(LEVEL) << "[";
184150

151+
LOG(LEVEL) << "[ writePixels ";
152+
writePixels(path);
153+
LOG(LEVEL) << "] writePixels ";
185154

186155
LOG(LEVEL) << "[ writeIntersectData " ;
187156
const char* fold = SPath::Dirname(path);

CSGOptiX/Frame.h

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ HMM: lots of overlap between this and SGLFW
1515
#include "squad.h"
1616
#include "plog/Severity.h"
1717

18-
struct SIMG ;
1918
#include "CSGOPTIX_API_EXPORT.hh"
2019

2120
struct CSGOPTIX_API Frame
@@ -27,9 +26,7 @@ struct CSGOPTIX_API Frame
2726
int height ;
2827
int depth ;
2928
int channels ;
30-
int jpg_quality ;
3129

32-
SIMG* img ;
3330
unsigned num_pixels ;
3431

3532
std::vector<float4> isect ;
@@ -55,24 +52,14 @@ struct CSGOPTIX_API Frame
5552
void download_(bool flip_vertical);
5653
void download(); // with flip_vertical:true
5754
void download_inverted(); // with flip_vertical:false
58-
void snap(const char* path );
55+
void snap(const char* path);
5956

60-
private:
57+
private:
58+
void flipPixelVertical();
59+
void writePixels(const char* path) const;
60+
void writeIsect(const char* dir, const char* name) const;
6161

62-
void write(const char* outdir, int quality=0) const ;
63-
64-
void writePNG(const char* path) const ;
65-
void writePNG(const char* dir, const char* name) const ;
66-
67-
void writeJPG(const char* path, int quality=0) const ;
68-
void writeJPG(const char* dir, const char* name, int quality=0) const ;
69-
70-
void writeIsect( const char* dir, const char* name) const ;
71-
72-
73-
unsigned getNumPixels() const ;
74-
unsigned char* getPixelData() const ;
75-
float* getIntersectData() const ;
62+
float* getIntersectData() const;
7663

7764
#ifdef WITH_FRAME_PHOTON
7865
void writeFPhoton( const char* dir, const char* name) const ;

CSGOptiX/tests/CSGOptiXRenderInteractiveTest.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,11 @@ inline void CSGOptiXRenderInteractiveTest::init()
134134

135135
}
136136

137-
138137
/**
139138
CSGOptiXRenderInteractiveTest::handle_snap_cx
140139
----------------------------------------------
141140
142-
Saves ray trace geometry screenshots when certain keys pressed.
141+
Saves ray trace geometry frame dumps when certain keys pressed.
143142
Formerly done between render_launch and unmap
144143
145144
**/
@@ -219,4 +218,3 @@ int main(int argc, char** argv)
219218
}
220219
return 0 ;
221220
}
222-

qudarap/QTexRotate.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void QTexRotate<T>::rotate(float theta)
3838

3939
cudaDeviceSynchronize();
4040
cudaCheckErrors("cudaDeviceSynchronize");
41-
// Fatal error: cudaDeviceSynchronize (linear filtering not supported for non-float type at SIMGStandaloneTest.cu:123)
41+
// Fatal error: cudaDeviceSynchronize (linear filtering not supported for non-float type)
4242

4343
if(rotate_dst == nullptr)
4444
{
@@ -52,4 +52,3 @@ void QTexRotate<T>::rotate(float theta)
5252

5353
template struct QUDARAP_API QTexRotate<uchar4>;
5454

55-

qudarap/tests/QTexRotateTest.cc

Lines changed: 0 additions & 61 deletions
This file was deleted.

sysrap/CMakeLists.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -553,16 +553,6 @@ list(APPEND HEADERS
553553
${IPH}
554554
${PYJS}
555555
)
556-
557-
558-
set(WITH_SIMG YES)
559-
if(WITH_SIMG)
560-
list(APPEND HEADERS stb_image.h stb_image_write.h)
561-
list(APPEND HEADERS SIMG.h )
562-
list(APPEND HEADERS SIMG_Frame.h )
563-
endif()
564-
565-
566556
set(WITH_NP YES)
567557

568558

0 commit comments

Comments
 (0)