Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ashlinrichardson committed Oct 27, 2019
1 parent ed95dd6 commit f8111cb
Show file tree
Hide file tree
Showing 14 changed files with 255 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ vri*
*.tar.gz
bin*
test*
*.pyc
Empty file modified CODE_OF_CONDUCT.md
100644 → 100755
Empty file.
Empty file modified CONTRIBUTING.md
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified R/plot.R
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
27 changes: 27 additions & 0 deletions cpp/ansicolor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once
#ifndef HEADER_ANSICOLOR_H
#define HEADER_ANSICOLOR_H
#define KNRM "\x1B[0m" //normal
#define KBLK "\x1B[30m" //black
#define KRED "\x1B[31m" //red
#define KGRN "\x1B[32m" //green
#define KYEL "\x1B[33m" //yellow
#define KBLU "\x1B[34m" //blue
#define KMAG "\x1B[35m" //magenta
#define KCYN "\x1B[36m" //cyan
#define KWHT "\x1B[37m" //white
#define KBLD "\x1B[1m" //bold
#define KRES "\x1B[0m" //reset
#define KITA "\x1B[3m" //italics
#define KUND "\x1B[4m" //underline
#define KSTR "\x1B[9m" //strikethrough
#define KINV "\x1B[7m" //inverseON
#define BBLK "\x1B[30m" //black
#define BRED "\x1B[31m" //red
#define BGRN "\x1B[32m" //green
#define BYEL "\x1B[33m" //yellow
#define BBLU "\x1B[34m" //blue
#define BMAG "\x1B[35m" //magenta
#define BCYN "\x1B[36m" //cyan
#define BWHT "\x1B[37m" //white
#endif
212 changes: 212 additions & 0 deletions cpp/misc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
#ifndef _MISC_H_
#define _MISC_H_
//---------------------------------------------------------------------------//
// misc.h: helper functions //
// date: 20190124 //
//---------------------------------------------------------------------------//

/* shorthand for for loops from 0 to N */
#define for0(i,n) for(i = 0; i < n; i++)

#define STR_MAX 16384

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<vector>
#include<string>
#include<sstream>
#include<fstream>
#include<iostream>
#include<limits.h>
#include<memory.h>
#include<pthread.h>
#include<algorithm>
#include"ansicolor.h"

#include <algorithm>
#include <cctype>
#include <locale>


using namespace std;

#include <stdio.h> /* defines FILENAME_MAX */
#ifdef WINDOWS
#include <direct.h>
#define _cwd _getcwd
#else
#include <unistd.h>
#define _cwd getcwd
#endif

void rewind(ifstream &a);

#define str string
string cwd();

/* split a string (a-la python) */
vector<string> split(string s, char delim);
vector<string> split(string s); // comma
vector<string> split_special(string s); // comma with possible commas inside quotation marks!
string join(const char * delim, vector<string> s);

template<class T> std::ostream& operator << (std::ostream& os, const std::vector<T>& v){
os << "[";
for (typename std::vector<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii){
os << " '" << *ii << "'";
}
os << "]";
return os;
}

template<class T> std::ostream& operator << (std::ostream& os, const std::set<T>& v){
os << "{";
for (typename std::set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii){
os << " " << *ii;
}
os << "}";
return os;
}

template<class A, class B> std::ostream& operator << (std::ostream& os, const std::map<A, B>& v){
os << "{" << endl;
for (typename std::map<A, B>::const_iterator ii = v.begin(); ii != v.end(); ++ii){
os << ii->first << ":" << ii->second << ","; //endl;
}
os << "}" << endl;
return os;
}

void err(string msg);

void err(const char * msg);

/* allocate memory */
inline void * alloc(size_t nb){
void * d = malloc(nb);
if(!d){
printf("%zu\n", nb);
err("failed to allocate memory");
}
memset(d, '\0', nb);
return d;
}


//a trim from start (in place)
static inline void ltrim(std::string &s){
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int ch){
return !std::isspace(ch);
}
));
}

// trim from end (in place)
static inline void rtrim(std::string &s){
s.erase(std::find_if(s.rbegin(), s.rend(), [](int ch){
return !std::isspace(ch);
}
).base(), s.end());
}

// trim from both ends (in place)
static inline void trim(std::string &s){
ltrim(s);
rtrim(s);
}

// trim from start (copying): not implemented properly
static inline std::string ltrim_copy(std::string s){
ltrim(s);
return s;
}

// trim from end (copying): not implemented properly
static inline std::string rtrim_copy(std::string s){
rtrim(s);
return s;
}

// trim from both ends (copying): not implemented properly
static inline std::string trim_copy(std::string s){
trim(s);
return s;
}

static inline void trim(std::string &s, char delim){
str ret("");
int end = s.size() - 1;
int start = 0;
while(s[start] == delim) start += 1;
while(s[end] == delim) end -= 1;
s = s.substr(start, 1 + end - start);
}

#define strip trim

/* convert to lower case */
static void inline lower(std::string & s){
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
}

static inline std::string lower_copy(std::string &s){
string r(s);
std::transform(r.begin(), r.end(), r.begin(), ::tolower);
return r;
}

/* get size of file pointer */
size_t size(FILE * f);
size_t fsize(string fn);

// in-memory reader (writer to be implemented)
// note this should be able to modulate between available protocols (like ifstream, ofstream, etc. , fwrite, fread, if available)

FILE * wopen(string fn);

class f_idx{
public: // float, index tuple object
float d;
unsigned int idx;
f_idx(float d_ = 0., unsigned int idx_ = 0){
d = d_;
idx = idx_;
}
f_idx(const f_idx &a){
d = a.d;
idx = a.idx;
}
};

bool operator<(const f_idx& a, const f_idx&b);

// read header file
void hread(str hfn, size_t & nrow, size_t & ncol, size_t & nband);
void hwrite(str hfn, size_t nrow, size_t ncol, size_t nband);

float * falloc(size_t nf);

// read binary file
float * bread(str bfn, size_t nrow, size_t ncol, size_t nband);

extern pthread_mutex_t print_mutex;
void cprint(str s);
/*
pthread_mutex_lock(&print_mutex);
cout << s << endl;
pthread_mutex_unlock(&print_mutex);
*/

int hsv_to_rgb(float *r, float *g, float *b, float h, float s, float v);

str hdr_fn(str fn);

/* get size of file pointer */
size_t size(FILE * f);
size_t fsize(string fn);
bool exists(str fn);


#endif
Empty file modified output/317.lab_wheel.bin.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified output/fastclust.bin_wheel.bin.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified output/kmeans.bin_wheel.bin.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified py/__init__.py
100644 → 100755
Empty file.
File renamed without changes.
28 changes: 15 additions & 13 deletions run
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,26 @@ bin/fast_cluster data/mS2.bin 10

rm data/*.png

bin/class_recode data/mS2.bin_fastclust.bin
bin/class_recode data/mS2.bin_kmeans.bin
class_recode data/mS2.bin_fastclust.bin
class_recode data/mS2.bin_kmeans.bin

mv data/mS2.bin_fastclust.bin_recode.bin data/mS2.bin_fastclust.bin
mv data/mS2.bin_kmeans.bin_recode.bin data/mS2.bin_kmeans.bin

bin/class_count data/mS2.bin_fastclust.bin
bin/class_count data/mS2.bin_kmeans.bin
class_count data/mS2.bin_fastclust.bin
class_count data/mS2.bin_kmeans.bin

bin/class_wheel data/mS2.bin_fastclust.bin
bin/class_wheel data/mS2.bin_kmeans.bin
class_wheel data/mS2.bin_fastclust.bin
class_wheel data/mS2.bin_kmeans.bin


bin/read_multispectral data/mS2.bin_fastclust.bin_wheel.bin 1
bin/read_multispectral data/mS2.bin_kmeans.bin_wheel.bin 1
read_multi data/mS2.bin_fastclust.bin_wheel.bin 1
read_multi data/mS2.bin_kmeans.bin_wheel.bin 1

class_match_onto data/mS2.bin_fastclust.bin data/mS2.bin_kmeans.bin data/fastclust_onto_kmeans.bin
class_wheel data/fastclust_onto_kmeans.bin
read_multi data/fastclust_onto_kmeans.bin_wheel.bin 1

bin/class_match_onto data/mS2.bin_fastclust.bin data/mS2.bin_kmeans.bin match.bin
exit


Expand All @@ -53,9 +55,9 @@ bin/class_wheel data/mS2.bin_kmeans.bin
bin/class_wheel data/mS2.bin_fastclust.bin_match.bin

rm data/*.png
bin/read_multispectral data/mS2.bin_fastclust.bin_match.bin_wheel.bin 1
#bin/read_multispectral data/mS2.bin_kmeans.bin_match.bin_wheel.bin 1
#bin/read_multispectral data/mS2.bin_fastclust.bin_wheel.bin 1
bin/read_multispectral data/mS2.bin_kmeans.bin_wheel.bin 1
bin/read_multi data/mS2.bin_fastclust.bin_match.bin_wheel.bin 1
#bin/read_multi data/mS2.bin_kmeans.bin_match.bin_wheel.bin 1
#bin/read_multi data/mS2.bin_fastclust.bin_wheel.bin 1
bin/read_multi data/mS2.bin_kmeans.bin_wheel.bin 1


0 comments on commit f8111cb

Please sign in to comment.