hexsha
stringlengths
40
40
repo
stringlengths
5
105
path
stringlengths
3
173
license
sequence
language
stringclasses
1 value
identifier
stringlengths
1
438
return_type
stringlengths
1
106
original_string
stringlengths
21
40.7k
original_docstring
stringlengths
18
13.4k
docstring
stringlengths
11
3.24k
docstring_tokens
sequence
code
stringlengths
14
20.4k
code_tokens
sequence
short_docstring
stringlengths
0
4.36k
short_docstring_tokens
sequence
comment
sequence
parameters
list
docstring_params
dict
7d953c0b9e55aca4af9148ab60dbf289af9d17ae
JeraKrs/linear-algebra-notes
src/Server Software/Assignment01/src/version01.c
[ "Apache-2.0" ]
C
run
void
void run() { int i; int ok; int markerID[100], studentID[100]; pthread_t markerT[100], studentT[100]; printf("S=%d M=%d K=%d N=%d T=%d D=%d\n", parameters.S, parameters.M, parameters.K, parameters.N, parameters.T, parameters.D); gettimeofday(&starttime, NULL); /* Save start of simulated time */ /* Initalise the global variable */ initialise(); /* Create S student threads */ for (i = 0; i < parameters.S; i++) { studentID[i] = i; ok = pthread_create(&studentT[i], NULL, student, &studentID[i]); if (ok != 0) { abort(); } } /* Create M marker threads */ for (i = 0; i < parameters.M; i++) { markerID[i] = i; ok = pthread_create(&markerT[i], NULL, marker, &markerID[i]); if (ok != 0) { abort(); } } /* With the threads now started, the session is in full swing ... */ delay(parameters.T - parameters.D); /* * When we reach here, this is the latest time a new demo could start. * You might want to do something here or soon after. */ /* Main thread sets timeout and sends signal to students and markers. */ ok = pthread_mutex_lock(&mut); if (ok != 0) { fprintf(stderr, "**ERROR**: Main thread is failed to " "acquire the locker (mut), %s.\n", strerror(errno)); abort(); } timeout = 1; ok = pthread_cond_broadcast(&c_student); if (ok != 0) { fprintf(stderr, "**ERROR**: Main thread is failed to " "broadcast students (c_student), %s.\n", strerror(errno)); abort(); } ok = pthread_cond_broadcast(&c_marker); if (ok != 0) { fprintf(stderr, "**ERROR**: Main thread is failed to " "broadcast markers (c_marker), %s.\n", strerror(errno)); abort(); } ok = pthread_mutex_unlock(&mut); if (ok != 0) { fprintf(stderr, "**ERROR**: Main thread is failed to " "release the locker (mut), %s.\n", strerror(errno)); abort(); } /* Wait for student threads to finish */ for (i = 0; i<parameters.S; i++) { ok = pthread_join(studentT[i], NULL); if (ok != 0) { abort(); } } /* Wait for marker threads to finish */ for (i = 0; i<parameters.M; i++) { ok = pthread_join(markerT[i], NULL); if (ok != 0) { abort(); } } /* Deallocates the memory */ free(markers); }
/* The function that runs the session. * You MAY want to modify this function. */
The function that runs the session. You MAY want to modify this function.
[ "The", "function", "that", "runs", "the", "session", ".", "You", "MAY", "want", "to", "modify", "this", "function", "." ]
void run() { int i; int ok; int markerID[100], studentID[100]; pthread_t markerT[100], studentT[100]; printf("S=%d M=%d K=%d N=%d T=%d D=%d\n", parameters.S, parameters.M, parameters.K, parameters.N, parameters.T, parameters.D); gettimeofday(&starttime, NULL); initialise(); for (i = 0; i < parameters.S; i++) { studentID[i] = i; ok = pthread_create(&studentT[i], NULL, student, &studentID[i]); if (ok != 0) { abort(); } } for (i = 0; i < parameters.M; i++) { markerID[i] = i; ok = pthread_create(&markerT[i], NULL, marker, &markerID[i]); if (ok != 0) { abort(); } } delay(parameters.T - parameters.D); ok = pthread_mutex_lock(&mut); if (ok != 0) { fprintf(stderr, "**ERROR**: Main thread is failed to " "acquire the locker (mut), %s.\n", strerror(errno)); abort(); } timeout = 1; ok = pthread_cond_broadcast(&c_student); if (ok != 0) { fprintf(stderr, "**ERROR**: Main thread is failed to " "broadcast students (c_student), %s.\n", strerror(errno)); abort(); } ok = pthread_cond_broadcast(&c_marker); if (ok != 0) { fprintf(stderr, "**ERROR**: Main thread is failed to " "broadcast markers (c_marker), %s.\n", strerror(errno)); abort(); } ok = pthread_mutex_unlock(&mut); if (ok != 0) { fprintf(stderr, "**ERROR**: Main thread is failed to " "release the locker (mut), %s.\n", strerror(errno)); abort(); } for (i = 0; i<parameters.S; i++) { ok = pthread_join(studentT[i], NULL); if (ok != 0) { abort(); } } for (i = 0; i<parameters.M; i++) { ok = pthread_join(markerT[i], NULL); if (ok != 0) { abort(); } } free(markers); }
[ "void", "run", "(", ")", "{", "int", "i", ";", "int", "ok", ";", "int", "markerID", "[", "100", "]", ",", "studentID", "[", "100", "]", ";", "pthread_t", "markerT", "[", "100", "]", ",", "studentT", "[", "100", "]", ";", "printf", "(", "\"", "\\n", "\"", ",", "parameters", ".", "S", ",", "parameters", ".", "M", ",", "parameters", ".", "K", ",", "parameters", ".", "N", ",", "parameters", ".", "T", ",", "parameters", ".", "D", ")", ";", "gettimeofday", "(", "&", "starttime", ",", "NULL", ")", ";", "initialise", "(", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "parameters", ".", "S", ";", "i", "++", ")", "{", "studentID", "[", "i", "]", "=", "i", ";", "ok", "=", "pthread_create", "(", "&", "studentT", "[", "i", "]", ",", "NULL", ",", "student", ",", "&", "studentID", "[", "i", "]", ")", ";", "if", "(", "ok", "!=", "0", ")", "{", "abort", "(", ")", ";", "}", "}", "for", "(", "i", "=", "0", ";", "i", "<", "parameters", ".", "M", ";", "i", "++", ")", "{", "markerID", "[", "i", "]", "=", "i", ";", "ok", "=", "pthread_create", "(", "&", "markerT", "[", "i", "]", ",", "NULL", ",", "marker", ",", "&", "markerID", "[", "i", "]", ")", ";", "if", "(", "ok", "!=", "0", ")", "{", "abort", "(", ")", ";", "}", "}", "delay", "(", "parameters", ".", "T", "-", "parameters", ".", "D", ")", ";", "ok", "=", "pthread_mutex_lock", "(", "&", "mut", ")", ";", "if", "(", "ok", "!=", "0", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\"", "\"", "\\n", "\"", ",", "strerror", "(", "errno", ")", ")", ";", "abort", "(", ")", ";", "}", "timeout", "=", "1", ";", "ok", "=", "pthread_cond_broadcast", "(", "&", "c_student", ")", ";", "if", "(", "ok", "!=", "0", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\"", "\"", "\\n", "\"", ",", "strerror", "(", "errno", ")", ")", ";", "abort", "(", ")", ";", "}", "ok", "=", "pthread_cond_broadcast", "(", "&", "c_marker", ")", ";", "if", "(", "ok", "!=", "0", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\"", "\"", "\\n", "\"", ",", "strerror", "(", "errno", ")", ")", ";", "abort", "(", ")", ";", "}", "ok", "=", "pthread_mutex_unlock", "(", "&", "mut", ")", ";", "if", "(", "ok", "!=", "0", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\"", "\"", "\\n", "\"", ",", "strerror", "(", "errno", ")", ")", ";", "abort", "(", ")", ";", "}", "for", "(", "i", "=", "0", ";", "i", "<", "parameters", ".", "S", ";", "i", "++", ")", "{", "ok", "=", "pthread_join", "(", "studentT", "[", "i", "]", ",", "NULL", ")", ";", "if", "(", "ok", "!=", "0", ")", "{", "abort", "(", ")", ";", "}", "}", "for", "(", "i", "=", "0", ";", "i", "<", "parameters", ".", "M", ";", "i", "++", ")", "{", "ok", "=", "pthread_join", "(", "markerT", "[", "i", "]", ",", "NULL", ")", ";", "if", "(", "ok", "!=", "0", ")", "{", "abort", "(", ")", ";", "}", "}", "free", "(", "markers", ")", ";", "}" ]
The function that runs the session.
[ "The", "function", "that", "runs", "the", "session", "." ]
[ "/* Save start of simulated time */", "/* Initalise the global variable */", "/* Create S student threads */", "/* Create M marker threads */", "/* With the threads now started, the session is in full swing ... */", "/* \n\t * When we reach here, this is the latest time a new demo could start.\n\t * You might want to do something here or soon after.\n\t */", "/* Main thread sets timeout and sends signal to students and markers. */", "/* Wait for student threads to finish */", "/* Wait for marker threads to finish */", "/* Deallocates the memory */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
b54398f698ea75e1ce3b749fbcbd6051dc3dd723
JeraKrs/linear-algebra-notes
src/Server Software/Assignment02/src/KV/queue.c
[ "Apache-2.0" ]
C
push_queue
int
int push_queue(Queue* que, int val) { if (que == NULL) return -1; if (full_queue(que) == 1) return 1; que->intArray[que->rear] = val; que->rear = (que->rear + 1) % QUEUE_SIZE; que->count = que->count + 1; return 0; }
/* 0 for success, 1 for failure and -1 for error */
0 for success, 1 for failure and -1 for error
[ "0", "for", "success", "1", "for", "failure", "and", "-", "1", "for", "error" ]
int push_queue(Queue* que, int val) { if (que == NULL) return -1; if (full_queue(que) == 1) return 1; que->intArray[que->rear] = val; que->rear = (que->rear + 1) % QUEUE_SIZE; que->count = que->count + 1; return 0; }
[ "int", "push_queue", "(", "Queue", "*", "que", ",", "int", "val", ")", "{", "if", "(", "que", "==", "NULL", ")", "return", "-1", ";", "if", "(", "full_queue", "(", "que", ")", "==", "1", ")", "return", "1", ";", "que", "->", "intArray", "[", "que", "->", "rear", "]", "=", "val", ";", "que", "->", "rear", "=", "(", "que", "->", "rear", "+", "1", ")", "%", "QUEUE_SIZE", ";", "que", "->", "count", "=", "que", "->", "count", "+", "1", ";", "return", "0", ";", "}" ]
0 for success, 1 for failure and -1 for error
[ "0", "for", "success", "1", "for", "failure", "and", "-", "1", "for", "error" ]
[]
[ { "param": "que", "type": "Queue" }, { "param": "val", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "que", "type": "Queue", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "val", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
b54398f698ea75e1ce3b749fbcbd6051dc3dd723
JeraKrs/linear-algebra-notes
src/Server Software/Assignment02/src/KV/queue.c
[ "Apache-2.0" ]
C
pop_queue
int
int pop_queue(Queue* que, int* val) { if (que == NULL) return -1; if (empty_queue(que) == 1) return 1; *val = que->intArray[que->front]; que->front = (que->front + 1) % QUEUE_SIZE; que->count = que->count - 1; return 0; }
/* 0 for success, 1 for failure and -1 for error */
0 for success, 1 for failure and -1 for error
[ "0", "for", "success", "1", "for", "failure", "and", "-", "1", "for", "error" ]
int pop_queue(Queue* que, int* val) { if (que == NULL) return -1; if (empty_queue(que) == 1) return 1; *val = que->intArray[que->front]; que->front = (que->front + 1) % QUEUE_SIZE; que->count = que->count - 1; return 0; }
[ "int", "pop_queue", "(", "Queue", "*", "que", ",", "int", "*", "val", ")", "{", "if", "(", "que", "==", "NULL", ")", "return", "-1", ";", "if", "(", "empty_queue", "(", "que", ")", "==", "1", ")", "return", "1", ";", "*", "val", "=", "que", "->", "intArray", "[", "que", "->", "front", "]", ";", "que", "->", "front", "=", "(", "que", "->", "front", "+", "1", ")", "%", "QUEUE_SIZE", ";", "que", "->", "count", "=", "que", "->", "count", "-", "1", ";", "return", "0", ";", "}" ]
0 for success, 1 for failure and -1 for error
[ "0", "for", "success", "1", "for", "failure", "and", "-", "1", "for", "error" ]
[]
[ { "param": "que", "type": "Queue" }, { "param": "val", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "que", "type": "Queue", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "val", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
b54398f698ea75e1ce3b749fbcbd6051dc3dd723
JeraKrs/linear-algebra-notes
src/Server Software/Assignment02/src/KV/queue.c
[ "Apache-2.0" ]
C
free_queue
int
int free_queue(Queue* que) { if (que == NULL) return -1; free(que); return 0; }
/* 0 for success and -1 for error */
0 for success and -1 for error
[ "0", "for", "success", "and", "-", "1", "for", "error" ]
int free_queue(Queue* que) { if (que == NULL) return -1; free(que); return 0; }
[ "int", "free_queue", "(", "Queue", "*", "que", ")", "{", "if", "(", "que", "==", "NULL", ")", "return", "-1", ";", "free", "(", "que", ")", ";", "return", "0", ";", "}" ]
0 for success and -1 for error
[ "0", "for", "success", "and", "-", "1", "for", "error" ]
[]
[ { "param": "que", "type": "Queue" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "que", "type": "Queue", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
0f5f241dbb7244f414ab67ea90597de8104af276
TeamMolecule/f00dsimpleserial
simpleserial.c
[ "MIT" ]
C
simpleserial_init
void
void simpleserial_init() { num_commands = 0; simpleserial_addcmd('v', 0, check_version); }
// Set up the SimpleSerial module by preparing internal commands // This just adds the "v" command for now...
Set up the SimpleSerial module by preparing internal commands This just adds the "v" command for now
[ "Set", "up", "the", "SimpleSerial", "module", "by", "preparing", "internal", "commands", "This", "just", "adds", "the", "\"", "v", "\"", "command", "for", "now" ]
void simpleserial_init() { num_commands = 0; simpleserial_addcmd('v', 0, check_version); }
[ "void", "simpleserial_init", "(", ")", "{", "num_commands", "=", "0", ";", "simpleserial_addcmd", "(", "'", "'", ",", "0", ",", "check_version", ")", ";", "}" ]
Set up the SimpleSerial module by preparing internal commands This just adds the "v" command for now...
[ "Set", "up", "the", "SimpleSerial", "module", "by", "preparing", "internal", "commands", "This", "just", "adds", "the", "\"", "v", "\"", "command", "for", "now", "..." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
3153ba7c47be62fa0ff905783d3672b00efd1f01
ludovicbarre/tfm
platform/ext/target/stm/common/stm32l5xx/accelerator/sha256_alt.c
[ "BSD-3-Clause" ]
C
mbedtls_zeroize
void
static void mbedtls_zeroize(void *v, size_t n) { volatile unsigned char *p = (unsigned char *)v; while (n--) { *p++ = 0; } }
/* Implementation that should never be optimized out by the compiler */
Implementation that should never be optimized out by the compiler
[ "Implementation", "that", "should", "never", "be", "optimized", "out", "by", "the", "compiler" ]
static void mbedtls_zeroize(void *v, size_t n) { volatile unsigned char *p = (unsigned char *)v; while (n--) { *p++ = 0; } }
[ "static", "void", "mbedtls_zeroize", "(", "void", "*", "v", ",", "size_t", "n", ")", "{", "volatile", "unsigned", "char", "*", "p", "=", "(", "unsigned", "char", "*", ")", "v", ";", "while", "(", "n", "--", ")", "{", "*", "p", "++", "=", "0", ";", "}", "}" ]
Implementation that should never be optimized out by the compiler
[ "Implementation", "that", "should", "never", "be", "optimized", "out", "by", "the", "compiler" ]
[]
[ { "param": "v", "type": "void" }, { "param": "n", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "v", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "n", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
8e4f3ac6377042eaf5473604c00f234333dec345
ludovicbarre/tfm
lib/ext/cryptocell-312-runtime/codesafe/src/mbedtls_api/cc_ecp_internal.c
[ "BSD-3-Clause" ]
C
cc_ecp_gen_keypair_base
int
int cc_ecp_gen_keypair_base( mbedtls_ecp_group *grp, const mbedtls_ecp_point *G, mbedtls_mpi *d, mbedtls_ecp_point *Q, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) { /* Input parameters validation */ if (NULL == grp || NULL == Q || NULL == d || NULL == G || f_rng == NULL || p_rng == NULL) { CC_PAL_LOG_ERR("Error - NULL pointer exception\n"); return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); } #if defined(ECP_MONTGOMERY) if( ecp_get_type( grp ) == ECP_TYPE_25519 ) { return ecp_mont_gen_keypair_base(G, d, Q, f_rng, p_rng); } #endif /* ECP_MONTGOMERY */ #if defined(ECP_SHORTWEIERSTRASS) if( ecp_get_type( grp ) == ECP_TYPE_SHORT_WEIERSTRASS ) { return ecp_wrst_gen_keypair_base(grp, G, d, Q, f_rng, p_rng); } #endif /* ECP_SHORTWEIERSTRASS */ return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); }
/* ECP_SHORTWEIERSTRASS */ /* * Generate a keypair with configurable base point */
ECP_SHORTWEIERSTRASS Generate a keypair with configurable base point
[ "ECP_SHORTWEIERSTRASS", "Generate", "a", "keypair", "with", "configurable", "base", "point" ]
int cc_ecp_gen_keypair_base( mbedtls_ecp_group *grp, const mbedtls_ecp_point *G, mbedtls_mpi *d, mbedtls_ecp_point *Q, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) { if (NULL == grp || NULL == Q || NULL == d || NULL == G || f_rng == NULL || p_rng == NULL) { CC_PAL_LOG_ERR("Error - NULL pointer exception\n"); return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); } #if defined(ECP_MONTGOMERY) if( ecp_get_type( grp ) == ECP_TYPE_25519 ) { return ecp_mont_gen_keypair_base(G, d, Q, f_rng, p_rng); } #endif #if defined(ECP_SHORTWEIERSTRASS) if( ecp_get_type( grp ) == ECP_TYPE_SHORT_WEIERSTRASS ) { return ecp_wrst_gen_keypair_base(grp, G, d, Q, f_rng, p_rng); } #endif return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); }
[ "int", "cc_ecp_gen_keypair_base", "(", "mbedtls_ecp_group", "*", "grp", ",", "const", "mbedtls_ecp_point", "*", "G", ",", "mbedtls_mpi", "*", "d", ",", "mbedtls_ecp_point", "*", "Q", ",", "int", "(", "*", "f_rng", ")", "(", "void", "*", ",", "unsigned", "char", "*", ",", "size_t", ")", ",", "void", "*", "p_rng", ")", "{", "if", "(", "NULL", "==", "grp", "||", "NULL", "==", "Q", "||", "NULL", "==", "d", "||", "NULL", "==", "G", "||", "f_rng", "==", "NULL", "||", "p_rng", "==", "NULL", ")", "{", "CC_PAL_LOG_ERR", "(", "\"", "\\n", "\"", ")", ";", "return", "(", "MBEDTLS_ERR_ECP_BAD_INPUT_DATA", ")", ";", "}", "#if", "defined", "(", "ECP_MONTGOMERY", ")", "\n", "if", "(", "ecp_get_type", "(", "grp", ")", "==", "ECP_TYPE_25519", ")", "{", "return", "ecp_mont_gen_keypair_base", "(", "G", ",", "d", ",", "Q", ",", "f_rng", ",", "p_rng", ")", ";", "}", "#endif", "#if", "defined", "(", "ECP_SHORTWEIERSTRASS", ")", "\n", "if", "(", "ecp_get_type", "(", "grp", ")", "==", "ECP_TYPE_SHORT_WEIERSTRASS", ")", "{", "return", "ecp_wrst_gen_keypair_base", "(", "grp", ",", "G", ",", "d", ",", "Q", ",", "f_rng", ",", "p_rng", ")", ";", "}", "#endif", "return", "(", "MBEDTLS_ERR_ECP_BAD_INPUT_DATA", ")", ";", "}" ]
ECP_SHORTWEIERSTRASS Generate a keypair with configurable base point
[ "ECP_SHORTWEIERSTRASS", "Generate", "a", "keypair", "with", "configurable", "base", "point" ]
[ "/* Input parameters validation */", "/* ECP_MONTGOMERY */", "/* ECP_SHORTWEIERSTRASS */" ]
[ { "param": "grp", "type": "mbedtls_ecp_group" }, { "param": "G", "type": "mbedtls_ecp_point" }, { "param": "d", "type": "mbedtls_mpi" }, { "param": "Q", "type": "mbedtls_ecp_point" }, { "param": "f_rng", "type": "int" }, { "param": "p_rng", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "grp", "type": "mbedtls_ecp_group", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "G", "type": "mbedtls_ecp_point", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "d", "type": "mbedtls_mpi", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "Q", "type": "mbedtls_ecp_point", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "f_rng", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "p_rng", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
bdce8490ab7d327b2f2c92b25b69ebb85390cc91
ludovicbarre/tfm
lib/ext/cryptocell-312-runtime/host/src/tests/integration_cc3x/runtime_integration_test/run_integration_test.c
[ "BSD-3-Clause" ]
C
runIt_executer
void
static void* runIt_executer(void *params) { RunItError_t rc = RUNIT_ERROR__OK; const char* TEST_NAME = "All Tests"; uint32_t testIter = 0; CC_UNUSED_PARAM(params); RUNIT_PRINT("cc312 runtime integration test\n"); RUNIT_PRINT("---------------------------------------------------------------\n"); /* Initialise runtime integration perf engine */ runIt_perfInit(); runIt_printMbedtlsAltConfig(); RUNIT_PRINT_HEADER(); gRunItPrintEnable = 1; runIt_regApi(); for (testIter = 1; testIter <= RUNIT_TEST_ITER_MAX; ++testIter) { RUNIT_TEST_START(TEST_NAME); /* Init libraries */ RUNIT_ASSERT(runIt_init() == RUNIT_ERROR__OK); #if !defined(RUNIT_PIE_ENABLED) rc += runIt_aesTest(); rc += runIt_srpTest(); rc += runIt_shaTest(); rc += runIt_ccmTest(); rc += runIt_gcmTest(); rc += runIt_rsaTest(); rc += runIt_ecdsaTest(); rc += runIt_ecdhTest(); rc += runIt_eciesTest(); rc += runIt_ctrDrbgTest(); rc += runIt_ChachaTest(); rc += runIt_macTest(); rc += runIt_dhmTest(); rc += runIt_extDmaTest(); #endif /* RUNIT_PIE_ENABLED */ rc += runIt_keyDerivationTest(); rc += runIt_assetProvTest(); rc += runIt_secureBootTest(); g_runIt_executerRc = rc; RUNIT_TEST_RESULT(TEST_NAME); /* continue to next test only if all passed */ RUNIT_ASSERT(rc == RUNIT_ERROR__OK); /* disable printing of next tests */ gRunItPrintEnable = 0; /* indicate progress */ RUNIT_PRINT("Test %u/%u completed\n", (unsigned int)testIter, RUNIT_TEST_ITER_MAX); runIt_finish(); } bail: runIt_perfDump(); CC_PAL_PERF_DUMP(); return NULL; }
/** * @brief Executor function. Called from a side thread to perform the sequence of tests. * @note This is a workaround the issue that CC API requires DMA-able stack. * When using Test_PalThreadCreate we are able to ensure that the stack is DMA-able. * @param params Not used */
@brief Executor function. Called from a side thread to perform the sequence of tests. @note This is a workaround the issue that CC API requires DMA-able stack. When using Test_PalThreadCreate we are able to ensure that the stack is DMA-able. @param params Not used
[ "@brief", "Executor", "function", ".", "Called", "from", "a", "side", "thread", "to", "perform", "the", "sequence", "of", "tests", ".", "@note", "This", "is", "a", "workaround", "the", "issue", "that", "CC", "API", "requires", "DMA", "-", "able", "stack", ".", "When", "using", "Test_PalThreadCreate", "we", "are", "able", "to", "ensure", "that", "the", "stack", "is", "DMA", "-", "able", ".", "@param", "params", "Not", "used" ]
static void* runIt_executer(void *params) { RunItError_t rc = RUNIT_ERROR__OK; const char* TEST_NAME = "All Tests"; uint32_t testIter = 0; CC_UNUSED_PARAM(params); RUNIT_PRINT("cc312 runtime integration test\n"); RUNIT_PRINT("---------------------------------------------------------------\n"); runIt_perfInit(); runIt_printMbedtlsAltConfig(); RUNIT_PRINT_HEADER(); gRunItPrintEnable = 1; runIt_regApi(); for (testIter = 1; testIter <= RUNIT_TEST_ITER_MAX; ++testIter) { RUNIT_TEST_START(TEST_NAME); RUNIT_ASSERT(runIt_init() == RUNIT_ERROR__OK); #if !defined(RUNIT_PIE_ENABLED) rc += runIt_aesTest(); rc += runIt_srpTest(); rc += runIt_shaTest(); rc += runIt_ccmTest(); rc += runIt_gcmTest(); rc += runIt_rsaTest(); rc += runIt_ecdsaTest(); rc += runIt_ecdhTest(); rc += runIt_eciesTest(); rc += runIt_ctrDrbgTest(); rc += runIt_ChachaTest(); rc += runIt_macTest(); rc += runIt_dhmTest(); rc += runIt_extDmaTest(); #endif rc += runIt_keyDerivationTest(); rc += runIt_assetProvTest(); rc += runIt_secureBootTest(); g_runIt_executerRc = rc; RUNIT_TEST_RESULT(TEST_NAME); RUNIT_ASSERT(rc == RUNIT_ERROR__OK); gRunItPrintEnable = 0; RUNIT_PRINT("Test %u/%u completed\n", (unsigned int)testIter, RUNIT_TEST_ITER_MAX); runIt_finish(); } bail: runIt_perfDump(); CC_PAL_PERF_DUMP(); return NULL; }
[ "static", "void", "*", "runIt_executer", "(", "void", "*", "params", ")", "{", "RunItError_t", "rc", "=", "RUNIT_ERROR__OK", ";", "const", "char", "*", "TEST_NAME", "=", "\"", "\"", ";", "uint32_t", "testIter", "=", "0", ";", "CC_UNUSED_PARAM", "(", "params", ")", ";", "RUNIT_PRINT", "(", "\"", "\\n", "\"", ")", ";", "RUNIT_PRINT", "(", "\"", "\\n", "\"", ")", ";", "runIt_perfInit", "(", ")", ";", "runIt_printMbedtlsAltConfig", "(", ")", ";", "RUNIT_PRINT_HEADER", "(", ")", ";", "gRunItPrintEnable", "=", "1", ";", "runIt_regApi", "(", ")", ";", "for", "(", "testIter", "=", "1", ";", "testIter", "<=", "RUNIT_TEST_ITER_MAX", ";", "++", "testIter", ")", "{", "RUNIT_TEST_START", "(", "TEST_NAME", ")", ";", "RUNIT_ASSERT", "(", "runIt_init", "(", ")", "==", "RUNIT_ERROR__OK", ")", ";", "#if", "!", "defined", "(", "RUNIT_PIE_ENABLED", ")", "\n", "rc", "+=", "runIt_aesTest", "(", ")", ";", "rc", "+=", "runIt_srpTest", "(", ")", ";", "rc", "+=", "runIt_shaTest", "(", ")", ";", "rc", "+=", "runIt_ccmTest", "(", ")", ";", "rc", "+=", "runIt_gcmTest", "(", ")", ";", "rc", "+=", "runIt_rsaTest", "(", ")", ";", "rc", "+=", "runIt_ecdsaTest", "(", ")", ";", "rc", "+=", "runIt_ecdhTest", "(", ")", ";", "rc", "+=", "runIt_eciesTest", "(", ")", ";", "rc", "+=", "runIt_ctrDrbgTest", "(", ")", ";", "rc", "+=", "runIt_ChachaTest", "(", ")", ";", "rc", "+=", "runIt_macTest", "(", ")", ";", "rc", "+=", "runIt_dhmTest", "(", ")", ";", "rc", "+=", "runIt_extDmaTest", "(", ")", ";", "#endif", "rc", "+=", "runIt_keyDerivationTest", "(", ")", ";", "rc", "+=", "runIt_assetProvTest", "(", ")", ";", "rc", "+=", "runIt_secureBootTest", "(", ")", ";", "g_runIt_executerRc", "=", "rc", ";", "RUNIT_TEST_RESULT", "(", "TEST_NAME", ")", ";", "RUNIT_ASSERT", "(", "rc", "==", "RUNIT_ERROR__OK", ")", ";", "gRunItPrintEnable", "=", "0", ";", "RUNIT_PRINT", "(", "\"", "\\n", "\"", ",", "(", "unsigned", "int", ")", "testIter", ",", "RUNIT_TEST_ITER_MAX", ")", ";", "runIt_finish", "(", ")", ";", "}", "bail", ":", "runIt_perfDump", "(", ")", ";", "CC_PAL_PERF_DUMP", "(", ")", ";", "return", "NULL", ";", "}" ]
@brief Executor function.
[ "@brief", "Executor", "function", "." ]
[ "/* Initialise runtime integration perf engine */", "/* Init libraries */", "/* RUNIT_PIE_ENABLED */", "/* continue to next test only if all passed */", "/* disable printing of next tests */", "/* indicate progress */" ]
[ { "param": "params", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "params", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4e5a2f4abdc619ab2793c8a78abb6726b21b93cf
ludovicbarre/tfm
secure_fw/partitions/protected_storage/ps_encrypted_object.c
[ "BSD-3-Clause" ]
C
ps_object_auth_decrypt
psa_status_t
static psa_status_t ps_object_auth_decrypt(uint32_t fid, uint32_t cur_size, struct ps_object_t *obj) { psa_status_t err; uint8_t *p_obj_data = (uint8_t *)&obj->header.info; size_t out_len; err = ps_crypto_setkey(); if (err != PSA_SUCCESS) { return err; } (void)tfm_memcpy(ps_crypto_buf, p_obj_data, cur_size); /* Use File ID as a part of the associated data to authenticate * the object in the FS. The tag will be stored in the object table and * not as a part of the object's data stored in the FS. */ err = ps_crypto_auth_and_decrypt(&obj->header.crypto, (const uint8_t *)&fid, sizeof(fid), ps_crypto_buf, cur_size, p_obj_data, sizeof(*obj) - sizeof(obj->header.crypto), &out_len); if (err != PSA_SUCCESS || out_len != cur_size) { (void)ps_crypto_destroykey(); return PSA_ERROR_GENERIC_ERROR; } return ps_crypto_destroykey(); }
/** * \brief Performs authenticated decryption on object data, with the header as * the associated data. * * \param[in] fid File ID * \param[in] cur_size Size of the object data to decrypt * \param[in,out] obj Pointer to the object structure to authenticate and * fill in with the decrypted data. The tag of the object * is the one stored in the object table for the given * File ID. * * \return Returns error code as specified in \ref psa_status_t */
\brief Performs authenticated decryption on object data, with the header as the associated data. \param[in] fid File ID \param[in] cur_size Size of the object data to decrypt \param[in,out] obj Pointer to the object structure to authenticate and fill in with the decrypted data. The tag of the object is the one stored in the object table for the given File ID. \return Returns error code as specified in \ref psa_status_t
[ "\\", "brief", "Performs", "authenticated", "decryption", "on", "object", "data", "with", "the", "header", "as", "the", "associated", "data", ".", "\\", "param", "[", "in", "]", "fid", "File", "ID", "\\", "param", "[", "in", "]", "cur_size", "Size", "of", "the", "object", "data", "to", "decrypt", "\\", "param", "[", "in", "out", "]", "obj", "Pointer", "to", "the", "object", "structure", "to", "authenticate", "and", "fill", "in", "with", "the", "decrypted", "data", ".", "The", "tag", "of", "the", "object", "is", "the", "one", "stored", "in", "the", "object", "table", "for", "the", "given", "File", "ID", ".", "\\", "return", "Returns", "error", "code", "as", "specified", "in", "\\", "ref", "psa_status_t" ]
static psa_status_t ps_object_auth_decrypt(uint32_t fid, uint32_t cur_size, struct ps_object_t *obj) { psa_status_t err; uint8_t *p_obj_data = (uint8_t *)&obj->header.info; size_t out_len; err = ps_crypto_setkey(); if (err != PSA_SUCCESS) { return err; } (void)tfm_memcpy(ps_crypto_buf, p_obj_data, cur_size); err = ps_crypto_auth_and_decrypt(&obj->header.crypto, (const uint8_t *)&fid, sizeof(fid), ps_crypto_buf, cur_size, p_obj_data, sizeof(*obj) - sizeof(obj->header.crypto), &out_len); if (err != PSA_SUCCESS || out_len != cur_size) { (void)ps_crypto_destroykey(); return PSA_ERROR_GENERIC_ERROR; } return ps_crypto_destroykey(); }
[ "static", "psa_status_t", "ps_object_auth_decrypt", "(", "uint32_t", "fid", ",", "uint32_t", "cur_size", ",", "struct", "ps_object_t", "*", "obj", ")", "{", "psa_status_t", "err", ";", "uint8_t", "*", "p_obj_data", "=", "(", "uint8_t", "*", ")", "&", "obj", "->", "header", ".", "info", ";", "size_t", "out_len", ";", "err", "=", "ps_crypto_setkey", "(", ")", ";", "if", "(", "err", "!=", "PSA_SUCCESS", ")", "{", "return", "err", ";", "}", "(", "void", ")", "tfm_memcpy", "(", "ps_crypto_buf", ",", "p_obj_data", ",", "cur_size", ")", ";", "err", "=", "ps_crypto_auth_and_decrypt", "(", "&", "obj", "->", "header", ".", "crypto", ",", "(", "const", "uint8_t", "*", ")", "&", "fid", ",", "sizeof", "(", "fid", ")", ",", "ps_crypto_buf", ",", "cur_size", ",", "p_obj_data", ",", "sizeof", "(", "*", "obj", ")", "-", "sizeof", "(", "obj", "->", "header", ".", "crypto", ")", ",", "&", "out_len", ")", ";", "if", "(", "err", "!=", "PSA_SUCCESS", "||", "out_len", "!=", "cur_size", ")", "{", "(", "void", ")", "ps_crypto_destroykey", "(", ")", ";", "return", "PSA_ERROR_GENERIC_ERROR", ";", "}", "return", "ps_crypto_destroykey", "(", ")", ";", "}" ]
\brief Performs authenticated decryption on object data, with the header as the associated data.
[ "\\", "brief", "Performs", "authenticated", "decryption", "on", "object", "data", "with", "the", "header", "as", "the", "associated", "data", "." ]
[ "/* Use File ID as a part of the associated data to authenticate\n * the object in the FS. The tag will be stored in the object table and\n * not as a part of the object's data stored in the FS.\n */" ]
[ { "param": "fid", "type": "uint32_t" }, { "param": "cur_size", "type": "uint32_t" }, { "param": "obj", "type": "struct ps_object_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fid", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cur_size", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "obj", "type": "struct ps_object_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4e5a2f4abdc619ab2793c8a78abb6726b21b93cf
ludovicbarre/tfm
secure_fw/partitions/protected_storage/ps_encrypted_object.c
[ "BSD-3-Clause" ]
C
ps_object_auth_encrypt
psa_status_t
static psa_status_t ps_object_auth_encrypt(uint32_t fid, uint32_t cur_size, struct ps_object_t *obj) { psa_status_t err; uint8_t *p_obj_data = (uint8_t *)&obj->header.info; size_t out_len; err = ps_crypto_setkey(); if (err != PSA_SUCCESS) { return err; } /* FIXME: should have an IV per object with key diversification */ /* Get a new IV for each encryption */ ps_crypto_get_iv(&obj->header.crypto); /* Use File ID as a part of the associated data to authenticate * the object in the FS. The tag will be stored in the object table and * not as a part of the object's data stored in the FS. */ err = ps_crypto_encrypt_and_tag(&obj->header.crypto, (const uint8_t *)&fid, sizeof(fid), p_obj_data, cur_size, ps_crypto_buf, sizeof(ps_crypto_buf), &out_len); if (err != PSA_SUCCESS || out_len != cur_size) { (void)ps_crypto_destroykey(); return PSA_ERROR_GENERIC_ERROR; } (void)tfm_memcpy(p_obj_data, ps_crypto_buf, cur_size); return ps_crypto_destroykey(); }
/** * \brief Performs authenticated encryption on object data, with the header as * the associated data. * * \param[in] fid File ID * \param[in] cur_size Size of the object data to encrypt * \param[out] obj Pointer to the object structure to authenticate and * fill in with the encrypted data. * * \return Returns error code as specified in \ref psa_status_t */
\brief Performs authenticated encryption on object data, with the header as the associated data. \param[in] fid File ID \param[in] cur_size Size of the object data to encrypt \param[out] obj Pointer to the object structure to authenticate and fill in with the encrypted data. \return Returns error code as specified in \ref psa_status_t
[ "\\", "brief", "Performs", "authenticated", "encryption", "on", "object", "data", "with", "the", "header", "as", "the", "associated", "data", ".", "\\", "param", "[", "in", "]", "fid", "File", "ID", "\\", "param", "[", "in", "]", "cur_size", "Size", "of", "the", "object", "data", "to", "encrypt", "\\", "param", "[", "out", "]", "obj", "Pointer", "to", "the", "object", "structure", "to", "authenticate", "and", "fill", "in", "with", "the", "encrypted", "data", ".", "\\", "return", "Returns", "error", "code", "as", "specified", "in", "\\", "ref", "psa_status_t" ]
static psa_status_t ps_object_auth_encrypt(uint32_t fid, uint32_t cur_size, struct ps_object_t *obj) { psa_status_t err; uint8_t *p_obj_data = (uint8_t *)&obj->header.info; size_t out_len; err = ps_crypto_setkey(); if (err != PSA_SUCCESS) { return err; } ps_crypto_get_iv(&obj->header.crypto); err = ps_crypto_encrypt_and_tag(&obj->header.crypto, (const uint8_t *)&fid, sizeof(fid), p_obj_data, cur_size, ps_crypto_buf, sizeof(ps_crypto_buf), &out_len); if (err != PSA_SUCCESS || out_len != cur_size) { (void)ps_crypto_destroykey(); return PSA_ERROR_GENERIC_ERROR; } (void)tfm_memcpy(p_obj_data, ps_crypto_buf, cur_size); return ps_crypto_destroykey(); }
[ "static", "psa_status_t", "ps_object_auth_encrypt", "(", "uint32_t", "fid", ",", "uint32_t", "cur_size", ",", "struct", "ps_object_t", "*", "obj", ")", "{", "psa_status_t", "err", ";", "uint8_t", "*", "p_obj_data", "=", "(", "uint8_t", "*", ")", "&", "obj", "->", "header", ".", "info", ";", "size_t", "out_len", ";", "err", "=", "ps_crypto_setkey", "(", ")", ";", "if", "(", "err", "!=", "PSA_SUCCESS", ")", "{", "return", "err", ";", "}", "ps_crypto_get_iv", "(", "&", "obj", "->", "header", ".", "crypto", ")", ";", "err", "=", "ps_crypto_encrypt_and_tag", "(", "&", "obj", "->", "header", ".", "crypto", ",", "(", "const", "uint8_t", "*", ")", "&", "fid", ",", "sizeof", "(", "fid", ")", ",", "p_obj_data", ",", "cur_size", ",", "ps_crypto_buf", ",", "sizeof", "(", "ps_crypto_buf", ")", ",", "&", "out_len", ")", ";", "if", "(", "err", "!=", "PSA_SUCCESS", "||", "out_len", "!=", "cur_size", ")", "{", "(", "void", ")", "ps_crypto_destroykey", "(", ")", ";", "return", "PSA_ERROR_GENERIC_ERROR", ";", "}", "(", "void", ")", "tfm_memcpy", "(", "p_obj_data", ",", "ps_crypto_buf", ",", "cur_size", ")", ";", "return", "ps_crypto_destroykey", "(", ")", ";", "}" ]
\brief Performs authenticated encryption on object data, with the header as the associated data.
[ "\\", "brief", "Performs", "authenticated", "encryption", "on", "object", "data", "with", "the", "header", "as", "the", "associated", "data", "." ]
[ "/* FIXME: should have an IV per object with key diversification */", "/* Get a new IV for each encryption */", "/* Use File ID as a part of the associated data to authenticate\n * the object in the FS. The tag will be stored in the object table and\n * not as a part of the object's data stored in the FS.\n */" ]
[ { "param": "fid", "type": "uint32_t" }, { "param": "cur_size", "type": "uint32_t" }, { "param": "obj", "type": "struct ps_object_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fid", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cur_size", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "obj", "type": "struct ps_object_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a232d537c79566f93b57a6410e0af2708a1c7b76
ludovicbarre/tfm
lib/ext/cryptocell-312-runtime/codesafe/src/mbedtls_api/ecp_common.h
[ "BSD-3-Clause" ]
C
ecp_get_type
ecp_curve_type
static inline ecp_curve_type ecp_get_type(const mbedtls_ecp_group *grp) { if (grp->G.X.p == NULL) return (ECP_TYPE_NONE); if (grp->G.Y.p == NULL) return (ECP_TYPE_25519); else return (ECP_TYPE_SHORT_WEIERSTRASS); }
/** * \brief get the cfurve type * */
\brief get the cfurve type
[ "\\", "brief", "get", "the", "cfurve", "type" ]
static inline ecp_curve_type ecp_get_type(const mbedtls_ecp_group *grp) { if (grp->G.X.p == NULL) return (ECP_TYPE_NONE); if (grp->G.Y.p == NULL) return (ECP_TYPE_25519); else return (ECP_TYPE_SHORT_WEIERSTRASS); }
[ "static", "inline", "ecp_curve_type", "ecp_get_type", "(", "const", "mbedtls_ecp_group", "*", "grp", ")", "{", "if", "(", "grp", "->", "G", ".", "X", ".", "p", "==", "NULL", ")", "return", "(", "ECP_TYPE_NONE", ")", ";", "if", "(", "grp", "->", "G", ".", "Y", ".", "p", "==", "NULL", ")", "return", "(", "ECP_TYPE_25519", ")", ";", "else", "return", "(", "ECP_TYPE_SHORT_WEIERSTRASS", ")", ";", "}" ]
\brief get the cfurve type
[ "\\", "brief", "get", "the", "cfurve", "type" ]
[]
[ { "param": "grp", "type": "mbedtls_ecp_group" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "grp", "type": "mbedtls_ecp_group", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c93194b121783a0b6a22bb4489e6b0fe7a2ba1bc
DellaBitta/firebase-cpp-sdk
firestore/src/tests/util/event_accumulator.h
[ "Apache-2.0" ]
C
AwaitLocalEvent
T
T AwaitLocalEvent() { T event; do { event = Await(); } while (!HasPendingWrites(event)); return event; }
/** Waits for a snapshot with pending writes. */
Waits for a snapshot with pending writes.
[ "Waits", "for", "a", "snapshot", "with", "pending", "writes", "." ]
T AwaitLocalEvent() { T event; do { event = Await(); } while (!HasPendingWrites(event)); return event; }
[ "T", "AwaitLocalEvent", "(", ")", "{", "T", "event", ";", "do", "{", "event", "=", "Await", "(", ")", ";", "}", "while", "(", "!", "HasPendingWrites", "(", "event", ")", ")", ";", "return", "event", ";", "}" ]
Waits for a snapshot with pending writes.
[ "Waits", "for", "a", "snapshot", "with", "pending", "writes", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
c93194b121783a0b6a22bb4489e6b0fe7a2ba1bc
DellaBitta/firebase-cpp-sdk
firestore/src/tests/util/event_accumulator.h
[ "Apache-2.0" ]
C
AwaitRemoteEvent
T
T AwaitRemoteEvent() { T event; do { event = Await(); } while (HasPendingWrites(event)); return event; }
/** Waits for a snapshot that has no pending writes. */
Waits for a snapshot that has no pending writes.
[ "Waits", "for", "a", "snapshot", "that", "has", "no", "pending", "writes", "." ]
T AwaitRemoteEvent() { T event; do { event = Await(); } while (HasPendingWrites(event)); return event; }
[ "T", "AwaitRemoteEvent", "(", ")", "{", "T", "event", ";", "do", "{", "event", "=", "Await", "(", ")", ";", "}", "while", "(", "HasPendingWrites", "(", "event", ")", ")", ";", "return", "event", ";", "}" ]
Waits for a snapshot that has no pending writes.
[ "Waits", "for", "a", "snapshot", "that", "has", "no", "pending", "writes", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
c93194b121783a0b6a22bb4489e6b0fe7a2ba1bc
DellaBitta/firebase-cpp-sdk
firestore/src/tests/util/event_accumulator.h
[ "Apache-2.0" ]
C
AwaitCacheEvent
T
T AwaitCacheEvent() { T event; do { event = Await(); } while (!IsFromCache(event)); return event; }
/** * Waits for a snapshot that is from cache. * NOTE: Helper exists only in C++ test. Not in native SDK test yet. */
Waits for a snapshot that is from cache. NOTE: Helper exists only in C++ test. Not in native SDK test yet.
[ "Waits", "for", "a", "snapshot", "that", "is", "from", "cache", ".", "NOTE", ":", "Helper", "exists", "only", "in", "C", "++", "test", ".", "Not", "in", "native", "SDK", "test", "yet", "." ]
T AwaitCacheEvent() { T event; do { event = Await(); } while (!IsFromCache(event)); return event; }
[ "T", "AwaitCacheEvent", "(", ")", "{", "T", "event", ";", "do", "{", "event", "=", "Await", "(", ")", ";", "}", "while", "(", "!", "IsFromCache", "(", "event", ")", ")", ";", "return", "event", ";", "}" ]
Waits for a snapshot that is from cache.
[ "Waits", "for", "a", "snapshot", "that", "is", "from", "cache", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
c93194b121783a0b6a22bb4489e6b0fe7a2ba1bc
DellaBitta/firebase-cpp-sdk
firestore/src/tests/util/event_accumulator.h
[ "Apache-2.0" ]
C
AwaitServerEvent
T
T AwaitServerEvent() { T event; do { event = Await(); } while (IsFromCache(event)); return event; }
/** * Waits for a snapshot that is not from cache. * NOTE: Helper exists only in C++ test. Not in native SDK test yet. */
Waits for a snapshot that is not from cache. NOTE: Helper exists only in C++ test. Not in native SDK test yet.
[ "Waits", "for", "a", "snapshot", "that", "is", "not", "from", "cache", ".", "NOTE", ":", "Helper", "exists", "only", "in", "C", "++", "test", ".", "Not", "in", "native", "SDK", "test", "yet", "." ]
T AwaitServerEvent() { T event; do { event = Await(); } while (IsFromCache(event)); return event; }
[ "T", "AwaitServerEvent", "(", ")", "{", "T", "event", ";", "do", "{", "event", "=", "Await", "(", ")", ";", "}", "while", "(", "IsFromCache", "(", "event", ")", ")", ";", "return", "event", ";", "}" ]
Waits for a snapshot that is not from cache.
[ "Waits", "for", "a", "snapshot", "that", "is", "not", "from", "cache", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
4bf846a1d7ff8d1721b6d7fc8db698ee26cd70c8
neonkingfr/MIDImonster
backends/midi.c
[ "BSD-2-Clause" ]
C
midi_handle_epn
void
static void midi_handle_epn(instance* inst, uint8_t chan, uint16_t control, uint16_t value){ midi_instance_data* data = (midi_instance_data*) inst->impl; midi_channel_ident ident = { .label = 0 }; channel* changed = NULL; channel_value val; //check for 3-byte update TODO //switching between nrpn and rpn clears all valid bits if(((data->epn_status[chan] & EPN_NRPN) && (control == 101 || control == 100)) || (!(data->epn_status[chan] & EPN_NRPN) && (control == 99 || control == 98))){ data->epn_status[chan] &= ~(EPN_NRPN | EPN_PARAMETER_LO | EPN_PARAMETER_HI); } //setting an address always invalidates the value valid bits if(control >= 98 && control <= 101){ data->epn_status[chan] &= ~(EPN_VALUE_HI /*| EPN_VALUE_LO*/); } //parameter hi if(control == 101 || control == 99){ data->epn_control[chan] &= 0x7F; data->epn_control[chan] |= value << 7; data->epn_status[chan] |= EPN_PARAMETER_HI | ((control == 99) ? EPN_NRPN : 0); if(control == 101 && value == 127){ data->epn_status[chan] &= ~EPN_PARAMETER_HI; } } //parameter lo if(control == 100 || control == 98){ data->epn_control[chan] &= ~0x7F; data->epn_control[chan] |= value & 0x7F; data->epn_status[chan] |= EPN_PARAMETER_LO | ((control == 98) ? EPN_NRPN : 0); if(control == 100 && value == 127){ data->epn_status[chan] &= ~EPN_PARAMETER_LO; } } //value hi, clears low, mark as update candidate if(control == 6 //check if parameter is set before accepting value update && ((data->epn_status[chan] & (EPN_PARAMETER_HI | EPN_PARAMETER_LO)) == (EPN_PARAMETER_HI | EPN_PARAMETER_LO))){ data->epn_value[chan] = value << 7; data->epn_status[chan] |= EPN_VALUE_HI; } //FIXME is the update order for the value bits fixed? //FIXME can there be standalone updates on CC 38? //value lo, flush the value if(control == 38 && data->epn_status[chan] & EPN_VALUE_HI){ data->epn_value[chan] &= ~0x7F; data->epn_value[chan] |= value & 0x7F; //FIXME not clearing the valid bit would allow for fast low-order updates data->epn_status[chan] &= ~EPN_VALUE_HI; if(midi_config.detect){ LOGPF("Incoming EPN data on channel %s.ch%d.%s%d", inst->name, chan, data->epn_status[chan] & EPN_NRPN ? "nrpn" : "rpn", data->epn_control[chan]); } //find the updated channel ident.fields.type = data->epn_status[chan] & EPN_NRPN ? nrpn : rpn; ident.fields.channel = chan; ident.fields.control = data->epn_control[chan]; val.normalised = (double) data->epn_value[chan] / 16383.0; //push the new value changed = mm_channel(inst, ident.label, 0); if(changed){ mm_channel_event(changed, val); } } }
//this state machine is used more-or-less verbatim in the winmidi, rtpmidi and jack backends - fixes need to be applied there, too
this state machine is used more-or-less verbatim in the winmidi, rtpmidi and jack backends - fixes need to be applied there, too
[ "this", "state", "machine", "is", "used", "more", "-", "or", "-", "less", "verbatim", "in", "the", "winmidi", "rtpmidi", "and", "jack", "backends", "-", "fixes", "need", "to", "be", "applied", "there", "too" ]
static void midi_handle_epn(instance* inst, uint8_t chan, uint16_t control, uint16_t value){ midi_instance_data* data = (midi_instance_data*) inst->impl; midi_channel_ident ident = { .label = 0 }; channel* changed = NULL; channel_value val; if(((data->epn_status[chan] & EPN_NRPN) && (control == 101 || control == 100)) || (!(data->epn_status[chan] & EPN_NRPN) && (control == 99 || control == 98))){ data->epn_status[chan] &= ~(EPN_NRPN | EPN_PARAMETER_LO | EPN_PARAMETER_HI); } if(control >= 98 && control <= 101){ data->epn_status[chan] &= ~(EPN_VALUE_HI ); } if(control == 101 || control == 99){ data->epn_control[chan] &= 0x7F; data->epn_control[chan] |= value << 7; data->epn_status[chan] |= EPN_PARAMETER_HI | ((control == 99) ? EPN_NRPN : 0); if(control == 101 && value == 127){ data->epn_status[chan] &= ~EPN_PARAMETER_HI; } } if(control == 100 || control == 98){ data->epn_control[chan] &= ~0x7F; data->epn_control[chan] |= value & 0x7F; data->epn_status[chan] |= EPN_PARAMETER_LO | ((control == 98) ? EPN_NRPN : 0); if(control == 100 && value == 127){ data->epn_status[chan] &= ~EPN_PARAMETER_LO; } } if(control == 6 && ((data->epn_status[chan] & (EPN_PARAMETER_HI | EPN_PARAMETER_LO)) == (EPN_PARAMETER_HI | EPN_PARAMETER_LO))){ data->epn_value[chan] = value << 7; data->epn_status[chan] |= EPN_VALUE_HI; } if(control == 38 && data->epn_status[chan] & EPN_VALUE_HI){ data->epn_value[chan] &= ~0x7F; data->epn_value[chan] |= value & 0x7F; data->epn_status[chan] &= ~EPN_VALUE_HI; if(midi_config.detect){ LOGPF("Incoming EPN data on channel %s.ch%d.%s%d", inst->name, chan, data->epn_status[chan] & EPN_NRPN ? "nrpn" : "rpn", data->epn_control[chan]); } ident.fields.type = data->epn_status[chan] & EPN_NRPN ? nrpn : rpn; ident.fields.channel = chan; ident.fields.control = data->epn_control[chan]; val.normalised = (double) data->epn_value[chan] / 16383.0; changed = mm_channel(inst, ident.label, 0); if(changed){ mm_channel_event(changed, val); } } }
[ "static", "void", "midi_handle_epn", "(", "instance", "*", "inst", ",", "uint8_t", "chan", ",", "uint16_t", "control", ",", "uint16_t", "value", ")", "{", "midi_instance_data", "*", "data", "=", "(", "midi_instance_data", "*", ")", "inst", "->", "impl", ";", "midi_channel_ident", "ident", "=", "{", ".", "label", "=", "0", "}", ";", "channel", "*", "changed", "=", "NULL", ";", "channel_value", "val", ";", "if", "(", "(", "(", "data", "->", "epn_status", "[", "chan", "]", "&", "EPN_NRPN", ")", "&&", "(", "control", "==", "101", "||", "control", "==", "100", ")", ")", "||", "(", "!", "(", "data", "->", "epn_status", "[", "chan", "]", "&", "EPN_NRPN", ")", "&&", "(", "control", "==", "99", "||", "control", "==", "98", ")", ")", ")", "{", "data", "->", "epn_status", "[", "chan", "]", "&=", "~", "(", "EPN_NRPN", "|", "EPN_PARAMETER_LO", "|", "EPN_PARAMETER_HI", ")", ";", "}", "if", "(", "control", ">=", "98", "&&", "control", "<=", "101", ")", "{", "data", "->", "epn_status", "[", "chan", "]", "&=", "~", "(", "EPN_VALUE_HI", ")", ";", "}", "if", "(", "control", "==", "101", "||", "control", "==", "99", ")", "{", "data", "->", "epn_control", "[", "chan", "]", "&=", "0x7F", ";", "data", "->", "epn_control", "[", "chan", "]", "|=", "value", "<<", "7", ";", "data", "->", "epn_status", "[", "chan", "]", "|=", "EPN_PARAMETER_HI", "|", "(", "(", "control", "==", "99", ")", "?", "EPN_NRPN", ":", "0", ")", ";", "if", "(", "control", "==", "101", "&&", "value", "==", "127", ")", "{", "data", "->", "epn_status", "[", "chan", "]", "&=", "~", "EPN_PARAMETER_HI", ";", "}", "}", "if", "(", "control", "==", "100", "||", "control", "==", "98", ")", "{", "data", "->", "epn_control", "[", "chan", "]", "&=", "~", "0x7F", ";", "data", "->", "epn_control", "[", "chan", "]", "|=", "value", "&", "0x7F", ";", "data", "->", "epn_status", "[", "chan", "]", "|=", "EPN_PARAMETER_LO", "|", "(", "(", "control", "==", "98", ")", "?", "EPN_NRPN", ":", "0", ")", ";", "if", "(", "control", "==", "100", "&&", "value", "==", "127", ")", "{", "data", "->", "epn_status", "[", "chan", "]", "&=", "~", "EPN_PARAMETER_LO", ";", "}", "}", "if", "(", "control", "==", "6", "&&", "(", "(", "data", "->", "epn_status", "[", "chan", "]", "&", "(", "EPN_PARAMETER_HI", "|", "EPN_PARAMETER_LO", ")", ")", "==", "(", "EPN_PARAMETER_HI", "|", "EPN_PARAMETER_LO", ")", ")", ")", "{", "data", "->", "epn_value", "[", "chan", "]", "=", "value", "<<", "7", ";", "data", "->", "epn_status", "[", "chan", "]", "|=", "EPN_VALUE_HI", ";", "}", "if", "(", "control", "==", "38", "&&", "data", "->", "epn_status", "[", "chan", "]", "&", "EPN_VALUE_HI", ")", "{", "data", "->", "epn_value", "[", "chan", "]", "&=", "~", "0x7F", ";", "data", "->", "epn_value", "[", "chan", "]", "|=", "value", "&", "0x7F", ";", "data", "->", "epn_status", "[", "chan", "]", "&=", "~", "EPN_VALUE_HI", ";", "if", "(", "midi_config", ".", "detect", ")", "{", "LOGPF", "(", "\"", "\"", ",", "inst", "->", "name", ",", "chan", ",", "data", "->", "epn_status", "[", "chan", "]", "&", "EPN_NRPN", "?", "\"", "\"", ":", "\"", "\"", ",", "data", "->", "epn_control", "[", "chan", "]", ")", ";", "}", "ident", ".", "fields", ".", "type", "=", "data", "->", "epn_status", "[", "chan", "]", "&", "EPN_NRPN", "?", "nrpn", ":", "rpn", ";", "ident", ".", "fields", ".", "channel", "=", "chan", ";", "ident", ".", "fields", ".", "control", "=", "data", "->", "epn_control", "[", "chan", "]", ";", "val", ".", "normalised", "=", "(", "double", ")", "data", "->", "epn_value", "[", "chan", "]", "/", "16383.0", ";", "changed", "=", "mm_channel", "(", "inst", ",", "ident", ".", "label", ",", "0", ")", ";", "if", "(", "changed", ")", "{", "mm_channel_event", "(", "changed", ",", "val", ")", ";", "}", "}", "}" ]
this state machine is used more-or-less verbatim in the winmidi, rtpmidi and jack backends - fixes need to be applied there, too
[ "this", "state", "machine", "is", "used", "more", "-", "or", "-", "less", "verbatim", "in", "the", "winmidi", "rtpmidi", "and", "jack", "backends", "-", "fixes", "need", "to", "be", "applied", "there", "too" ]
[ "//check for 3-byte update TODO", "//switching between nrpn and rpn clears all valid bits", "//setting an address always invalidates the value valid bits", "/*| EPN_VALUE_LO*/", "//parameter hi", "//parameter lo", "//value hi, clears low, mark as update candidate", "//check if parameter is set before accepting value update", "//FIXME is the update order for the value bits fixed?", "//FIXME can there be standalone updates on CC 38?", "//value lo, flush the value", "//FIXME not clearing the valid bit would allow for fast low-order updates", "//find the updated channel", "//push the new value" ]
[ { "param": "inst", "type": "instance" }, { "param": "chan", "type": "uint8_t" }, { "param": "control", "type": "uint16_t" }, { "param": "value", "type": "uint16_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "inst", "type": "instance", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "chan", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "control", "type": "uint16_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "value", "type": "uint16_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
fc07328515ea943efa0c299154e60889901891af
neonkingfr/MIDImonster
backends/wininput.c
[ "BSD-2-Clause" ]
C
wininput_mouse_normalize
void
static void wininput_mouse_normalize(long* x, long* y){ long normalized_x = (double) (*x - cfg.virtual_x) * (65535.0f / (double) cfg.virtual_width); long normalized_y = (double) (*y - cfg.virtual_y) * (65535.0f / (double) cfg.virtual_height); *x = normalized_x; *y = normalized_y; }
//for some reason, sendinput only takes "normalized absolute coordinates", which are never again used in the API
for some reason, sendinput only takes "normalized absolute coordinates", which are never again used in the API
[ "for", "some", "reason", "sendinput", "only", "takes", "\"", "normalized", "absolute", "coordinates", "\"", "which", "are", "never", "again", "used", "in", "the", "API" ]
static void wininput_mouse_normalize(long* x, long* y){ long normalized_x = (double) (*x - cfg.virtual_x) * (65535.0f / (double) cfg.virtual_width); long normalized_y = (double) (*y - cfg.virtual_y) * (65535.0f / (double) cfg.virtual_height); *x = normalized_x; *y = normalized_y; }
[ "static", "void", "wininput_mouse_normalize", "(", "long", "*", "x", ",", "long", "*", "y", ")", "{", "long", "normalized_x", "=", "(", "double", ")", "(", "*", "x", "-", "cfg", ".", "virtual_x", ")", "*", "(", "65535.0f", "/", "(", "double", ")", "cfg", ".", "virtual_width", ")", ";", "long", "normalized_y", "=", "(", "double", ")", "(", "*", "y", "-", "cfg", ".", "virtual_y", ")", "*", "(", "65535.0f", "/", "(", "double", ")", "cfg", ".", "virtual_height", ")", ";", "*", "x", "=", "normalized_x", ";", "*", "y", "=", "normalized_y", ";", "}" ]
for some reason, sendinput only takes "normalized absolute coordinates", which are never again used in the API
[ "for", "some", "reason", "sendinput", "only", "takes", "\"", "normalized", "absolute", "coordinates", "\"", "which", "are", "never", "again", "used", "in", "the", "API" ]
[]
[ { "param": "x", "type": "long" }, { "param": "y", "type": "long" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "x", "type": "long", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "y", "type": "long", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3d80b3eb4d4dead8581b52cabf0b3ae1f5de6c46
angelosettembre/Matrix_Multiplication_MPI
src/Matrix_Multiplication_MPI.c
[ "MIT" ]
C
allocateMatrix
void
void allocateMatrix(int **matrix, int size){ int i; int *contiguousItems = (int *)malloc(size*size*sizeof(int)); //ALLOCAZIONE DI SIZE*SIZE ELEMENTI CONTIGUI for(i=0;i<size;i++) matrix[i]= &contiguousItems[i*size]; //SI RENDE LA MATRICE COME UN ARRAY }
/*FUNZIONE PER L'ALLOCAZIONE DI MATRICI*/
FUNZIONE PER L'ALLOCAZIONE DI MATRICI
[ "FUNZIONE", "PER", "L", "'", "ALLOCAZIONE", "DI", "MATRICI" ]
void allocateMatrix(int **matrix, int size){ int i; int *contiguousItems = (int *)malloc(size*size*sizeof(int)); for(i=0;i<size;i++) matrix[i]= &contiguousItems[i*size]; }
[ "void", "allocateMatrix", "(", "int", "*", "*", "matrix", ",", "int", "size", ")", "{", "int", "i", ";", "int", "*", "contiguousItems", "=", "(", "int", "*", ")", "malloc", "(", "size", "*", "size", "*", "sizeof", "(", "int", ")", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "size", ";", "i", "++", ")", "matrix", "[", "i", "]", "=", "&", "contiguousItems", "[", "i", "*", "size", "]", ";", "}" ]
FUNZIONE PER L'ALLOCAZIONE DI MATRICI
[ "FUNZIONE", "PER", "L", "'", "ALLOCAZIONE", "DI", "MATRICI" ]
[ "//ALLOCAZIONE DI SIZE*SIZE ELEMENTI CONTIGUI", "//SI RENDE LA MATRICE COME UN ARRAY" ]
[ { "param": "matrix", "type": "int" }, { "param": "size", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "matrix", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "size", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3d80b3eb4d4dead8581b52cabf0b3ae1f5de6c46
angelosettembre/Matrix_Multiplication_MPI
src/Matrix_Multiplication_MPI.c
[ "MIT" ]
C
createMatrix
void
void createMatrix(int **matrix, int size){ int i,j; for(i = 0; i<size; i++){ for(j=0; j<size; j++){ matrix[i][j] = rand() % 10; //Valori tra 0 e 10 escluso } } }
/*FUNZIONE PER LA CREAZIONE DELLE MATRICI A E B*/
FUNZIONE PER LA CREAZIONE DELLE MATRICI A E B
[ "FUNZIONE", "PER", "LA", "CREAZIONE", "DELLE", "MATRICI", "A", "E", "B" ]
void createMatrix(int **matrix, int size){ int i,j; for(i = 0; i<size; i++){ for(j=0; j<size; j++){ matrix[i][j] = rand() % 10; } } }
[ "void", "createMatrix", "(", "int", "*", "*", "matrix", ",", "int", "size", ")", "{", "int", "i", ",", "j", ";", "for", "(", "i", "=", "0", ";", "i", "<", "size", ";", "i", "++", ")", "{", "for", "(", "j", "=", "0", ";", "j", "<", "size", ";", "j", "++", ")", "{", "matrix", "[", "i", "]", "[", "j", "]", "=", "rand", "(", ")", "%", "10", ";", "}", "}", "}" ]
FUNZIONE PER LA CREAZIONE DELLE MATRICI A E B
[ "FUNZIONE", "PER", "LA", "CREAZIONE", "DELLE", "MATRICI", "A", "E", "B" ]
[ "//Valori tra 0 e 10 escluso" ]
[ { "param": "matrix", "type": "int" }, { "param": "size", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "matrix", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "size", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3d80b3eb4d4dead8581b52cabf0b3ae1f5de6c46
angelosettembre/Matrix_Multiplication_MPI
src/Matrix_Multiplication_MPI.c
[ "MIT" ]
C
printMatrix
void
void printMatrix(int **matrix, int size){ int i,j; for(i = 0; i<size; i++){ printf("\n\t["); for(j=0; j<size; j++){ printf(" %d ",matrix[i][j]); } printf("]"); } printf("\n"); }
/*FUNZIONE PER LA STAMPA DELLE MATRICI*/
FUNZIONE PER LA STAMPA DELLE MATRICI
[ "FUNZIONE", "PER", "LA", "STAMPA", "DELLE", "MATRICI" ]
void printMatrix(int **matrix, int size){ int i,j; for(i = 0; i<size; i++){ printf("\n\t["); for(j=0; j<size; j++){ printf(" %d ",matrix[i][j]); } printf("]"); } printf("\n"); }
[ "void", "printMatrix", "(", "int", "*", "*", "matrix", ",", "int", "size", ")", "{", "int", "i", ",", "j", ";", "for", "(", "i", "=", "0", ";", "i", "<", "size", ";", "i", "++", ")", "{", "printf", "(", "\"", "\\n", "\\t", "\"", ")", ";", "for", "(", "j", "=", "0", ";", "j", "<", "size", ";", "j", "++", ")", "{", "printf", "(", "\"", "\"", ",", "matrix", "[", "i", "]", "[", "j", "]", ")", ";", "}", "printf", "(", "\"", "\"", ")", ";", "}", "printf", "(", "\"", "\\n", "\"", ")", ";", "}" ]
FUNZIONE PER LA STAMPA DELLE MATRICI
[ "FUNZIONE", "PER", "LA", "STAMPA", "DELLE", "MATRICI" ]
[]
[ { "param": "matrix", "type": "int" }, { "param": "size", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "matrix", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "size", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
eb9eea591b540a046c1c54bf5963d47f465716e4
Dennisbonke/toaruos
apps/panel.c
[ "NCSA" ]
C
sig_int
void
static void sig_int(int sig) { printf("Received shutdown signal in panel!\n"); _continue = 0; signal(SIGINT, sig_int); }
/* Handle SIGINT by telling other threads (clock) to shut down */
Handle SIGINT by telling other threads (clock) to shut down
[ "Handle", "SIGINT", "by", "telling", "other", "threads", "(", "clock", ")", "to", "shut", "down" ]
static void sig_int(int sig) { printf("Received shutdown signal in panel!\n"); _continue = 0; signal(SIGINT, sig_int); }
[ "static", "void", "sig_int", "(", "int", "sig", ")", "{", "printf", "(", "\"", "\\n", "\"", ")", ";", "_continue", "=", "0", ";", "signal", "(", "SIGINT", ",", "sig_int", ")", ";", "}" ]
Handle SIGINT by telling other threads (clock) to shut down
[ "Handle", "SIGINT", "by", "telling", "other", "threads", "(", "clock", ")", "to", "shut", "down" ]
[]
[ { "param": "sig", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sig", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
632942d5db3397a9d5c1f686cc1c3d3bd4d653a3
csea-lab/csea-lab
Libas/4sbdy_else/Xcode files/comm.c
[ "MIT" ]
C
die
void
static void die( void ) { int port; // mexPrintf( "COMM 'die'\n" ); if( string != NULL ) { free(string); string = NULL; } for( port=0; port<sizeof(portInfo)/sizeof(PORTINFO); port++ ) { if( portInfo[port].fd != -1 ) { closeSerialPort( &portInfo[port] ); portInfo[port].fd = -1; free( portInfo[port].readBufferPtr ); portInfo[port].readBufferPtr = NULL; } } }
// Close all ports if COMM gets cleared or MATLAB exits //
Close all ports if COMM gets cleared or MATLAB exits
[ "Close", "all", "ports", "if", "COMM", "gets", "cleared", "or", "MATLAB", "exits" ]
static void die( void ) { int port; if( string != NULL ) { free(string); string = NULL; } for( port=0; port<sizeof(portInfo)/sizeof(PORTINFO); port++ ) { if( portInfo[port].fd != -1 ) { closeSerialPort( &portInfo[port] ); portInfo[port].fd = -1; free( portInfo[port].readBufferPtr ); portInfo[port].readBufferPtr = NULL; } } }
[ "static", "void", "die", "(", "void", ")", "{", "int", "port", ";", "if", "(", "string", "!=", "NULL", ")", "{", "free", "(", "string", ")", ";", "string", "=", "NULL", ";", "}", "for", "(", "port", "=", "0", ";", "port", "<", "sizeof", "(", "portInfo", ")", "/", "sizeof", "(", "PORTINFO", ")", ";", "port", "++", ")", "{", "if", "(", "portInfo", "[", "port", "]", ".", "fd", "!=", "-1", ")", "{", "closeSerialPort", "(", "&", "portInfo", "[", "port", "]", ")", ";", "portInfo", "[", "port", "]", ".", "fd", "=", "-1", ";", "free", "(", "portInfo", "[", "port", "]", ".", "readBufferPtr", ")", ";", "portInfo", "[", "port", "]", ".", "readBufferPtr", "=", "NULL", ";", "}", "}", "}" ]
Close all ports if COMM gets cleared or MATLAB exits
[ "Close", "all", "ports", "if", "COMM", "gets", "cleared", "or", "MATLAB", "exits" ]
[ "// mexPrintf( \"COMM 'die'\\n\" );" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
206a9c22747540b7af82d70ef068757b33009315
cmgriffin/6502-Computer
supplements/AVR-input-expander/firmware/src/main.c
[ "MIT" ]
C
initGpio
void
void initGpio() { #ifdef PARALLEL_INPUT PORTB = 0xff; // enable all the pullups for easier debugging PORTD = 0xff; // enable all the pullups for easier debugging DDRC |= _BV(SER_PIN); // set serial pin as an output #else PORTC |= _BV(SER_PIN); // input by default, enable the pullup DDRB = 0xff; // configure as outputs, low by default DDRD = 0xff; // configure as outputs, low by default #endif PORTC |= _BV(SRCLK_PIN) | _BV(RCLK_PIN); // input by default, enable the pullups PCICR |= _BV(PCIE1); // enable pin change interupts for portc PCMSK1 |= _BV(PCINT8) | _BV(PCINT9); // enable the pin change interupt for SRCLK and RCLK pins }
// hold the input data once it is latched
hold the input data once it is latched
[ "hold", "the", "input", "data", "once", "it", "is", "latched" ]
void initGpio() { #ifdef PARALLEL_INPUT PORTB = 0xff; PORTD = 0xff; DDRC |= _BV(SER_PIN); #else PORTC |= _BV(SER_PIN); DDRB = 0xff; DDRD = 0xff; #endif PORTC |= _BV(SRCLK_PIN) | _BV(RCLK_PIN); s PCICR |= _BV(PCIE1); PCMSK1 |= _BV(PCINT8) | _BV(PCINT9); }
[ "void", "initGpio", "(", ")", "{", "#ifdef", "PARALLEL_INPUT", "PORTB", "=", "0xff", ";", "PORTD", "=", "0xff", ";", "DDRC", "|=", "_BV", "(", "SER_PIN", ")", ";", "#else", "PORTC", "|=", "_BV", "(", "SER_PIN", ")", ";", "DDRB", "=", "0xff", ";", "DDRD", "=", "0xff", ";", "#endif", "PORTC", "|=", "_BV", "(", "SRCLK_PIN", ")", "|", "_BV", "(", "RCLK_PIN", ")", ";", "PCICR", "|=", "_BV", "(", "PCIE1", ")", ";", "PCMSK1", "|=", "_BV", "(", "PCINT8", ")", "|", "_BV", "(", "PCINT9", ")", ";", "}" ]
hold the input data once it is latched
[ "hold", "the", "input", "data", "once", "it", "is", "latched" ]
[ "// enable all the pullups for easier debugging", "// enable all the pullups for easier debugging", "// set serial pin as an output", "// input by default, enable the pullup", "// configure as outputs, low by default", "// configure as outputs, low by default", "// input by default, enable the pullups", "// enable pin change interupts for portc", "// enable the pin change interupt for SRCLK and RCLK pins" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
4a28f43a9b2b05da44e18e4e0b7fb590688ddf78
silentbicycle/skel
src/main.c
[ "0BSD" ]
C
substitute_template
void
static void substitute_template(struct config *cfg) { static char tbuf[LINE_BUF_SZ]; char *line = NULL; while ((line = fgets(tbuf, sizeof(tbuf), cfg->template))) { sub_and_print_line(cfg, line); } }
/* Read the template from the file stream, line by line, * and print it (with variable substitutions). */
Read the template from the file stream, line by line, and print it (with variable substitutions).
[ "Read", "the", "template", "from", "the", "file", "stream", "line", "by", "line", "and", "print", "it", "(", "with", "variable", "substitutions", ")", "." ]
static void substitute_template(struct config *cfg) { static char tbuf[LINE_BUF_SZ]; char *line = NULL; while ((line = fgets(tbuf, sizeof(tbuf), cfg->template))) { sub_and_print_line(cfg, line); } }
[ "static", "void", "substitute_template", "(", "struct", "config", "*", "cfg", ")", "{", "static", "char", "tbuf", "[", "LINE_BUF_SZ", "]", ";", "char", "*", "line", "=", "NULL", ";", "while", "(", "(", "line", "=", "fgets", "(", "tbuf", ",", "sizeof", "(", "tbuf", ")", ",", "cfg", "->", "template", ")", ")", ")", "{", "sub_and_print_line", "(", "cfg", ",", "line", ")", ";", "}", "}" ]
Read the template from the file stream, line by line, and print it (with variable substitutions).
[ "Read", "the", "template", "from", "the", "file", "stream", "line", "by", "line", "and", "print", "it", "(", "with", "variable", "substitutions", ")", "." ]
[]
[ { "param": "cfg", "type": "struct config" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "cfg", "type": "struct config", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a86b0f46ba4404647d4ceb0abe6fb81969bdd0d1
roatis2/GameOfThreads
filesystem.c
[ "MIT" ]
C
read_dentry_by_index
int32_t
int32_t read_dentry_by_index (uint32_t index, dentry_t* dentry_index) { /* 1) take in inode index in memory 2) find specified inode 3) return address where that inode is in memory */ if(index >= bootBlock->inode_count || dentry_index == NULL){return -1;} strcpy(dentry_index->filename, bootBlock->directories[index].filename ); dentry_index->filetype = bootBlock->directories[index].filetype; dentry_index->inode_num = bootBlock->directories[index].inode_num; return 0; }
/* * read_dentry_by_index * DESCRIPTION: Reads the directory entry by index * INPUTS: index -- the directory index taken from read_dentry_by_name * dentry_index -- directory entry pointer used for read_directory_by_index * * OUTPUTS: None * RETURN VALUE: returns 0 or -1 * SIDE EFFECTS: Modifies global pointer to dentry struct */
read_dentry_by_index DESCRIPTION: Reads the directory entry by index INPUTS: index -- the directory index taken from read_dentry_by_name dentry_index -- directory entry pointer used for read_directory_by_index None RETURN VALUE: returns 0 or -1 SIDE EFFECTS: Modifies global pointer to dentry struct
[ "read_dentry_by_index", "DESCRIPTION", ":", "Reads", "the", "directory", "entry", "by", "index", "INPUTS", ":", "index", "--", "the", "directory", "index", "taken", "from", "read_dentry_by_name", "dentry_index", "--", "directory", "entry", "pointer", "used", "for", "read_directory_by_index", "None", "RETURN", "VALUE", ":", "returns", "0", "or", "-", "1", "SIDE", "EFFECTS", ":", "Modifies", "global", "pointer", "to", "dentry", "struct" ]
int32_t read_dentry_by_index (uint32_t index, dentry_t* dentry_index) { if(index >= bootBlock->inode_count || dentry_index == NULL){return -1;} strcpy(dentry_index->filename, bootBlock->directories[index].filename ); dentry_index->filetype = bootBlock->directories[index].filetype; dentry_index->inode_num = bootBlock->directories[index].inode_num; return 0; }
[ "int32_t", "read_dentry_by_index", "(", "uint32_t", "index", ",", "dentry_t", "*", "dentry_index", ")", "{", "if", "(", "index", ">=", "bootBlock", "->", "inode_count", "||", "dentry_index", "==", "NULL", ")", "{", "return", "-1", ";", "}", "strcpy", "(", "dentry_index", "->", "filename", ",", "bootBlock", "->", "directories", "[", "index", "]", ".", "filename", ")", ";", "dentry_index", "->", "filetype", "=", "bootBlock", "->", "directories", "[", "index", "]", ".", "filetype", ";", "dentry_index", "->", "inode_num", "=", "bootBlock", "->", "directories", "[", "index", "]", ".", "inode_num", ";", "return", "0", ";", "}" ]
read_dentry_by_index DESCRIPTION: Reads the directory entry by index INPUTS: index -- the directory index taken from read_dentry_by_name dentry_index -- directory entry pointer used for read_directory_by_index
[ "read_dentry_by_index", "DESCRIPTION", ":", "Reads", "the", "directory", "entry", "by", "index", "INPUTS", ":", "index", "--", "the", "directory", "index", "taken", "from", "read_dentry_by_name", "dentry_index", "--", "directory", "entry", "pointer", "used", "for", "read_directory_by_index" ]
[ "/*\n\t1) take in inode index in memory\n\t2) find specified inode\n\t3) return address where that inode is in memory\n\t*/" ]
[ { "param": "index", "type": "uint32_t" }, { "param": "dentry_index", "type": "dentry_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "index", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "dentry_index", "type": "dentry_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
02f8c0bf1d3003ff98d80309c3ad0bdee80da8b4
roatis2/GameOfThreads
syscall.c
[ "MIT" ]
C
parse_args
int8_t
int8_t parse_args(const uint8_t* command, uint8_t* filename, uint8_t* args) { // the command parameter in system execute will have the string that describes the command. // Possibly in this checkpoint, they would enter one word at a time instead of multiple commands // seperated by spaces. for example: entering "ls"(one word) to open current directory along versus // entering "ls mp1"(two words) to open mp1's directory. Trying to find a way to parse command by its SPACES int32_t start = 0; int32_t end = 0; //check valid inputs if(command == NULL || filename == NULL || args == NULL){return -1;} //check for leading spaces while(command[start] == SPACE) { start++; //check if buffer is full of spaces or premature newline or Null terminator if((command[end] == NEWLINE) || (command[end] == NOKE)){return -1;} } //find end of first word end = start; //move to end of name argument/check if reaching end of command buffer , use a limit on command size???? while((command[end] != SPACE) && (command[end] != NEWLINE) && (command[end] != NOKE) ) { filename[end-start] = command[end]; end++; } //add null terminator to filename filename[end-start] = NOKE; //check if reached the end of buffer or reached next arg start = end; while(command[start] == SPACE){start++;} //find end of args and use to index into arg buffer end = start; //copy remainder of buffer into args buffer with all spaces while(command[end] != NOKE && command[end] != NEWLINE ) { args[end - start] = command[end]; end++; } args[end-start] = NOKE; return 0; }
/* parse_args * DESCRIPTION: parse buffer into two space separated args first arg is placed in an array while the rest of the orig. buffer is placed in a third buffer * INPUT: command -- buffer to parse in 2 * filename -- buffer for first argument * args -- buffer for args * OUTPUT:NONE * RETURN: 0 on success, -1 on error * SIDE EFFECTS: */
parse_args DESCRIPTION: parse buffer into two space separated args first arg is placed in an array while the rest of the orig.
[ "parse_args", "DESCRIPTION", ":", "parse", "buffer", "into", "two", "space", "separated", "args", "first", "arg", "is", "placed", "in", "an", "array", "while", "the", "rest", "of", "the", "orig", "." ]
int8_t parse_args(const uint8_t* command, uint8_t* filename, uint8_t* args) { int32_t start = 0; int32_t end = 0; if(command == NULL || filename == NULL || args == NULL){return -1;} while(command[start] == SPACE) { start++; if((command[end] == NEWLINE) || (command[end] == NOKE)){return -1;} } end = start; while((command[end] != SPACE) && (command[end] != NEWLINE) && (command[end] != NOKE) ) { filename[end-start] = command[end]; end++; } filename[end-start] = NOKE; start = end; while(command[start] == SPACE){start++;} end = start; while(command[end] != NOKE && command[end] != NEWLINE ) { args[end - start] = command[end]; end++; } args[end-start] = NOKE; return 0; }
[ "int8_t", "parse_args", "(", "const", "uint8_t", "*", "command", ",", "uint8_t", "*", "filename", ",", "uint8_t", "*", "args", ")", "{", "int32_t", "start", "=", "0", ";", "int32_t", "end", "=", "0", ";", "if", "(", "command", "==", "NULL", "||", "filename", "==", "NULL", "||", "args", "==", "NULL", ")", "{", "return", "-1", ";", "}", "while", "(", "command", "[", "start", "]", "==", "SPACE", ")", "{", "start", "++", ";", "if", "(", "(", "command", "[", "end", "]", "==", "NEWLINE", ")", "||", "(", "command", "[", "end", "]", "==", "NOKE", ")", ")", "{", "return", "-1", ";", "}", "}", "end", "=", "start", ";", "while", "(", "(", "command", "[", "end", "]", "!=", "SPACE", ")", "&&", "(", "command", "[", "end", "]", "!=", "NEWLINE", ")", "&&", "(", "command", "[", "end", "]", "!=", "NOKE", ")", ")", "{", "filename", "[", "end", "-", "start", "]", "=", "command", "[", "end", "]", ";", "end", "++", ";", "}", "filename", "[", "end", "-", "start", "]", "=", "NOKE", ";", "start", "=", "end", ";", "while", "(", "command", "[", "start", "]", "==", "SPACE", ")", "{", "start", "++", ";", "}", "end", "=", "start", ";", "while", "(", "command", "[", "end", "]", "!=", "NOKE", "&&", "command", "[", "end", "]", "!=", "NEWLINE", ")", "{", "args", "[", "end", "-", "start", "]", "=", "command", "[", "end", "]", ";", "end", "++", ";", "}", "args", "[", "end", "-", "start", "]", "=", "NOKE", ";", "return", "0", ";", "}" ]
parse_args DESCRIPTION: parse buffer into two space separated args first arg is placed in an array while the rest of the orig.
[ "parse_args", "DESCRIPTION", ":", "parse", "buffer", "into", "two", "space", "separated", "args", "first", "arg", "is", "placed", "in", "an", "array", "while", "the", "rest", "of", "the", "orig", "." ]
[ "// the command parameter in system execute will have the string that describes the command.", "// Possibly in this checkpoint, they would enter one word at a time instead of multiple commands", "// seperated by spaces. for example: entering \"ls\"(one word) to open current directory along versus ", "// entering \"ls mp1\"(two words) to open mp1's directory. Trying to find a way to parse command by its SPACES", "//check valid inputs", "//check for leading spaces", "//check if buffer is full of spaces or premature newline or Null terminator", "//find end of first word", "//move to end of name argument/check if reaching end of command buffer , use a limit on command size????", "//add null terminator to filename", "//check if reached the end of buffer or reached next arg", "//find end of args and use to index into arg buffer", "//copy remainder of buffer into args buffer with all spaces" ]
[ { "param": "command", "type": "uint8_t" }, { "param": "filename", "type": "uint8_t" }, { "param": "args", "type": "uint8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "command", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "filename", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "args", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
37481b31bf5505f01a2369dc4c4e375d6a4cf5da
csylo/launchpad-tcp
lp2-tcp-receive-file/main.c
[ "BSD-3-Clause" ]
C
SimpleLinkWlanEventHandler
void
void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent) { if(!pWlanEvent) { return; } switch(pWlanEvent->Event) { case SL_WLAN_CONNECT_EVENT: { SET_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION); // // Information about the connected AP (like name, MAC etc) will be // available in 'slWlanConnectAsyncResponse_t'-Applications // can use it if required // // slWlanConnectAsyncResponse_t *pEventData = NULL; // pEventData = &pWlanEvent->EventData.STAandP2PModeWlanConnected; // // Copy new connection SSID and BSSID to global parameters memcpy(g_ucConnectionSSID,pWlanEvent->EventData. STAandP2PModeWlanConnected.ssid_name, pWlanEvent->EventData.STAandP2PModeWlanConnected.ssid_len); memcpy(g_ucConnectionBSSID, pWlanEvent->EventData.STAandP2PModeWlanConnected.bssid, SL_BSSID_LENGTH); } break; case SL_WLAN_DISCONNECT_EVENT: { slWlanConnectAsyncResponse_t* pEventData = NULL; CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION); CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED); pEventData = &pWlanEvent->EventData.STAandP2PModeDisconnected; // If the user has initiated 'Disconnect' request, //'reason_code' is SL_USER_INITIATED_DISCONNECTION if(SL_USER_INITIATED_DISCONNECTION == pEventData->reason_code) { UART_PRINT("[WLAN EVENT]Device disconnected from the AP: %s," "BSSID: %x:%x:%x:%x:%x:%x on application's request \n\r", g_ucConnectionSSID,g_ucConnectionBSSID[0], g_ucConnectionBSSID[1],g_ucConnectionBSSID[2], g_ucConnectionBSSID[3],g_ucConnectionBSSID[4], g_ucConnectionBSSID[5]); } else { UART_PRINT("[WLAN ERROR]Device disconnected from the AP AP: %s," "BSSID: %x:%x:%x:%x:%x:%x on an ERROR..!! \n\r", g_ucConnectionSSID,g_ucConnectionBSSID[0], g_ucConnectionBSSID[1],g_ucConnectionBSSID[2], g_ucConnectionBSSID[3],g_ucConnectionBSSID[4], g_ucConnectionBSSID[5]); } memset(g_ucConnectionSSID,0,sizeof(g_ucConnectionSSID)); memset(g_ucConnectionBSSID,0,sizeof(g_ucConnectionBSSID)); } break; default: { UART_PRINT("[WLAN EVENT] Unexpected event [0x%x]\n\r", pWlanEvent->Event); } break; } }
//***************************************************************************** // //! \brief The Function Handles WLAN Events //! //*****************************************************************************
\brief The Function Handles WLAN Events
[ "\\", "brief", "The", "Function", "Handles", "WLAN", "Events" ]
void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent) { if(!pWlanEvent) { return; } switch(pWlanEvent->Event) { case SL_WLAN_CONNECT_EVENT: { SET_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION); memcpy(g_ucConnectionSSID,pWlanEvent->EventData. STAandP2PModeWlanConnected.ssid_name, pWlanEvent->EventData.STAandP2PModeWlanConnected.ssid_len); memcpy(g_ucConnectionBSSID, pWlanEvent->EventData.STAandP2PModeWlanConnected.bssid, SL_BSSID_LENGTH); } break; case SL_WLAN_DISCONNECT_EVENT: { slWlanConnectAsyncResponse_t* pEventData = NULL; CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION); CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED); pEventData = &pWlanEvent->EventData.STAandP2PModeDisconnected; if(SL_USER_INITIATED_DISCONNECTION == pEventData->reason_code) { UART_PRINT("[WLAN EVENT]Device disconnected from the AP: %s," "BSSID: %x:%x:%x:%x:%x:%x on application's request \n\r", g_ucConnectionSSID,g_ucConnectionBSSID[0], g_ucConnectionBSSID[1],g_ucConnectionBSSID[2], g_ucConnectionBSSID[3],g_ucConnectionBSSID[4], g_ucConnectionBSSID[5]); } else { UART_PRINT("[WLAN ERROR]Device disconnected from the AP AP: %s," "BSSID: %x:%x:%x:%x:%x:%x on an ERROR..!! \n\r", g_ucConnectionSSID,g_ucConnectionBSSID[0], g_ucConnectionBSSID[1],g_ucConnectionBSSID[2], g_ucConnectionBSSID[3],g_ucConnectionBSSID[4], g_ucConnectionBSSID[5]); } memset(g_ucConnectionSSID,0,sizeof(g_ucConnectionSSID)); memset(g_ucConnectionBSSID,0,sizeof(g_ucConnectionBSSID)); } break; default: { UART_PRINT("[WLAN EVENT] Unexpected event [0x%x]\n\r", pWlanEvent->Event); } break; } }
[ "void", "SimpleLinkWlanEventHandler", "(", "SlWlanEvent_t", "*", "pWlanEvent", ")", "{", "if", "(", "!", "pWlanEvent", ")", "{", "return", ";", "}", "switch", "(", "pWlanEvent", "->", "Event", ")", "{", "case", "SL_WLAN_CONNECT_EVENT", ":", "{", "SET_STATUS_BIT", "(", "g_ulStatus", ",", "STATUS_BIT_CONNECTION", ")", ";", "memcpy", "(", "g_ucConnectionSSID", ",", "pWlanEvent", "->", "EventData", ".", "STAandP2PModeWlanConnected", ".", "ssid_name", ",", "pWlanEvent", "->", "EventData", ".", "STAandP2PModeWlanConnected", ".", "ssid_len", ")", ";", "memcpy", "(", "g_ucConnectionBSSID", ",", "pWlanEvent", "->", "EventData", ".", "STAandP2PModeWlanConnected", ".", "bssid", ",", "SL_BSSID_LENGTH", ")", ";", "}", "break", ";", "case", "SL_WLAN_DISCONNECT_EVENT", ":", "{", "slWlanConnectAsyncResponse_t", "*", "pEventData", "=", "NULL", ";", "CLR_STATUS_BIT", "(", "g_ulStatus", ",", "STATUS_BIT_CONNECTION", ")", ";", "CLR_STATUS_BIT", "(", "g_ulStatus", ",", "STATUS_BIT_IP_AQUIRED", ")", ";", "pEventData", "=", "&", "pWlanEvent", "->", "EventData", ".", "STAandP2PModeDisconnected", ";", "if", "(", "SL_USER_INITIATED_DISCONNECTION", "==", "pEventData", "->", "reason_code", ")", "{", "UART_PRINT", "(", "\"", "\"", "\"", "\\n", "\\r", "\"", ",", "g_ucConnectionSSID", ",", "g_ucConnectionBSSID", "[", "0", "]", ",", "g_ucConnectionBSSID", "[", "1", "]", ",", "g_ucConnectionBSSID", "[", "2", "]", ",", "g_ucConnectionBSSID", "[", "3", "]", ",", "g_ucConnectionBSSID", "[", "4", "]", ",", "g_ucConnectionBSSID", "[", "5", "]", ")", ";", "}", "else", "{", "UART_PRINT", "(", "\"", "\"", "\"", "\\n", "\\r", "\"", ",", "g_ucConnectionSSID", ",", "g_ucConnectionBSSID", "[", "0", "]", ",", "g_ucConnectionBSSID", "[", "1", "]", ",", "g_ucConnectionBSSID", "[", "2", "]", ",", "g_ucConnectionBSSID", "[", "3", "]", ",", "g_ucConnectionBSSID", "[", "4", "]", ",", "g_ucConnectionBSSID", "[", "5", "]", ")", ";", "}", "memset", "(", "g_ucConnectionSSID", ",", "0", ",", "sizeof", "(", "g_ucConnectionSSID", ")", ")", ";", "memset", "(", "g_ucConnectionBSSID", ",", "0", ",", "sizeof", "(", "g_ucConnectionBSSID", ")", ")", ";", "}", "break", ";", "default", ":", "{", "UART_PRINT", "(", "\"", "\\n", "\\r", "\"", ",", "pWlanEvent", "->", "Event", ")", ";", "}", "break", ";", "}", "}" ]
\brief The Function Handles WLAN Events
[ "\\", "brief", "The", "Function", "Handles", "WLAN", "Events" ]
[ "//\r", "// Information about the connected AP (like name, MAC etc) will be\r", "// available in 'slWlanConnectAsyncResponse_t'-Applications\r", "// can use it if required\r", "//\r", "// slWlanConnectAsyncResponse_t *pEventData = NULL;\r", "// pEventData = &pWlanEvent->EventData.STAandP2PModeWlanConnected;\r", "//\r", "// Copy new connection SSID and BSSID to global parameters\r", "// If the user has initiated 'Disconnect' request,\r", "//'reason_code' is SL_USER_INITIATED_DISCONNECTION\r" ]
[ { "param": "pWlanEvent", "type": "SlWlanEvent_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pWlanEvent", "type": "SlWlanEvent_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
37481b31bf5505f01a2369dc4c4e375d6a4cf5da
csylo/launchpad-tcp
lp2-tcp-receive-file/main.c
[ "BSD-3-Clause" ]
C
SimpleLinkNetAppEventHandler
void
void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent) { if(!pNetAppEvent) { return; } switch(pNetAppEvent->Event) { case SL_NETAPP_IPV4_IPACQUIRED_EVENT: { SlIpV4AcquiredAsync_t *pEventData = NULL; SET_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED); //Ip Acquired Event Data pEventData = &pNetAppEvent->EventData.ipAcquiredV4; g_ulIpAddr = pEventData->ip; //Gateway IP address g_ulGatewayIP = pEventData->gateway; } break; default: { UART_PRINT("[NETAPP EVENT] Unexpected event [0x%x] \n\r", pNetAppEvent->Event); } break; } }
//***************************************************************************** // //! \brief This function handles network events such as IP acquisition, IP //! leased, IP released etc. //! //*****************************************************************************
\brief This function handles network events such as IP acquisition, IP leased, IP released etc.
[ "\\", "brief", "This", "function", "handles", "network", "events", "such", "as", "IP", "acquisition", "IP", "leased", "IP", "released", "etc", "." ]
void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent) { if(!pNetAppEvent) { return; } switch(pNetAppEvent->Event) { case SL_NETAPP_IPV4_IPACQUIRED_EVENT: { SlIpV4AcquiredAsync_t *pEventData = NULL; SET_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED); pEventData = &pNetAppEvent->EventData.ipAcquiredV4; g_ulIpAddr = pEventData->ip; g_ulGatewayIP = pEventData->gateway; } break; default: { UART_PRINT("[NETAPP EVENT] Unexpected event [0x%x] \n\r", pNetAppEvent->Event); } break; } }
[ "void", "SimpleLinkNetAppEventHandler", "(", "SlNetAppEvent_t", "*", "pNetAppEvent", ")", "{", "if", "(", "!", "pNetAppEvent", ")", "{", "return", ";", "}", "switch", "(", "pNetAppEvent", "->", "Event", ")", "{", "case", "SL_NETAPP_IPV4_IPACQUIRED_EVENT", ":", "{", "SlIpV4AcquiredAsync_t", "*", "pEventData", "=", "NULL", ";", "SET_STATUS_BIT", "(", "g_ulStatus", ",", "STATUS_BIT_IP_AQUIRED", ")", ";", "pEventData", "=", "&", "pNetAppEvent", "->", "EventData", ".", "ipAcquiredV4", ";", "g_ulIpAddr", "=", "pEventData", "->", "ip", ";", "g_ulGatewayIP", "=", "pEventData", "->", "gateway", ";", "}", "break", ";", "default", ":", "{", "UART_PRINT", "(", "\"", "\\n", "\\r", "\"", ",", "pNetAppEvent", "->", "Event", ")", ";", "}", "break", ";", "}", "}" ]
\brief This function handles network events such as IP acquisition, IP leased, IP released etc.
[ "\\", "brief", "This", "function", "handles", "network", "events", "such", "as", "IP", "acquisition", "IP", "leased", "IP", "released", "etc", "." ]
[ "//Ip Acquired Event Data\r", "//Gateway IP address\r" ]
[ { "param": "pNetAppEvent", "type": "SlNetAppEvent_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pNetAppEvent", "type": "SlNetAppEvent_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
37481b31bf5505f01a2369dc4c4e375d6a4cf5da
csylo/launchpad-tcp
lp2-tcp-receive-file/main.c
[ "BSD-3-Clause" ]
C
SimpleLinkGeneralEventHandler
void
void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *pDevEvent){ if(!pDevEvent){ return; } // Most of the general errors are not FATAL are are to be handled // appropriately by the application // UART_PRINT("[GENERAL EVENT] - ID=[%d] Sender=[%d]\n\n", pDevEvent->EventData.deviceEvent.status, pDevEvent->EventData.deviceEvent.sender); }
//***************************************************************************** // //! \brief This function handles General Events //! //! \param[in] pDevEvent - Pointer to General Event Info //! //*****************************************************************************
\brief This function handles General Events \param[in] pDevEvent - Pointer to General Event Info
[ "\\", "brief", "This", "function", "handles", "General", "Events", "\\", "param", "[", "in", "]", "pDevEvent", "-", "Pointer", "to", "General", "Event", "Info" ]
void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *pDevEvent){ if(!pDevEvent){ return; } UART_PRINT("[GENERAL EVENT] - ID=[%d] Sender=[%d]\n\n", pDevEvent->EventData.deviceEvent.status, pDevEvent->EventData.deviceEvent.sender); }
[ "void", "SimpleLinkGeneralEventHandler", "(", "SlDeviceEvent_t", "*", "pDevEvent", ")", "{", "if", "(", "!", "pDevEvent", ")", "{", "return", ";", "}", "UART_PRINT", "(", "\"", "\\n", "\\n", "\"", ",", "pDevEvent", "->", "EventData", ".", "deviceEvent", ".", "status", ",", "pDevEvent", "->", "EventData", ".", "deviceEvent", ".", "sender", ")", ";", "}" ]
\brief This function handles General Events \param[in] pDevEvent - Pointer to General Event Info
[ "\\", "brief", "This", "function", "handles", "General", "Events", "\\", "param", "[", "in", "]", "pDevEvent", "-", "Pointer", "to", "General", "Event", "Info" ]
[ "// Most of the general errors are not FATAL are are to be handled\r", "// appropriately by the application\r", "//\r" ]
[ { "param": "pDevEvent", "type": "SlDeviceEvent_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pDevEvent", "type": "SlDeviceEvent_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
37481b31bf5505f01a2369dc4c4e375d6a4cf5da
csylo/launchpad-tcp
lp2-tcp-receive-file/main.c
[ "BSD-3-Clause" ]
C
SimpleLinkSockEventHandler
void
void SimpleLinkSockEventHandler(SlSockEvent_t *pSock) { if(!pSock){ return; } // This application doesn't work w/ socket - Events are not expected switch(pSock->Event){ case SL_SOCKET_TX_FAILED_EVENT: switch( pSock->socketAsyncEvent.SockTxFailData.status) { case SL_ECLOSE: UART_PRINT("[SOCK ERROR] - close socket (%d) operation " "failed to transmit all queued packets\n\n", pSock->socketAsyncEvent.SockTxFailData.sd); break; default: UART_PRINT("[SOCK ERROR] - TX FAILED : socket %d , reason " "(%d) \n\n", pSock->socketAsyncEvent.SockTxFailData.sd, pSock->socketAsyncEvent.SockTxFailData.status); break; } break; default: UART_PRINT("[SOCK EVENT] - Unexpected Event [%x0x]\n\n",pSock->Event); break; } }
//***************************************************************************** // //! This function handles socket events indication //! //! \param[in] pSock - Pointer to Socket Event Info //! //*****************************************************************************
This function handles socket events indication \param[in] pSock - Pointer to Socket Event Info
[ "This", "function", "handles", "socket", "events", "indication", "\\", "param", "[", "in", "]", "pSock", "-", "Pointer", "to", "Socket", "Event", "Info" ]
void SimpleLinkSockEventHandler(SlSockEvent_t *pSock) { if(!pSock){ return; } switch(pSock->Event){ case SL_SOCKET_TX_FAILED_EVENT: switch( pSock->socketAsyncEvent.SockTxFailData.status) { case SL_ECLOSE: UART_PRINT("[SOCK ERROR] - close socket (%d) operation " "failed to transmit all queued packets\n\n", pSock->socketAsyncEvent.SockTxFailData.sd); break; default: UART_PRINT("[SOCK ERROR] - TX FAILED : socket %d , reason " "(%d) \n\n", pSock->socketAsyncEvent.SockTxFailData.sd, pSock->socketAsyncEvent.SockTxFailData.status); break; } break; default: UART_PRINT("[SOCK EVENT] - Unexpected Event [%x0x]\n\n",pSock->Event); break; } }
[ "void", "SimpleLinkSockEventHandler", "(", "SlSockEvent_t", "*", "pSock", ")", "{", "if", "(", "!", "pSock", ")", "{", "return", ";", "}", "switch", "(", "pSock", "->", "Event", ")", "{", "case", "SL_SOCKET_TX_FAILED_EVENT", ":", "switch", "(", "pSock", "->", "socketAsyncEvent", ".", "SockTxFailData", ".", "status", ")", "{", "case", "SL_ECLOSE", ":", "UART_PRINT", "(", "\"", "\"", "\"", "\\n", "\\n", "\"", ",", "pSock", "->", "socketAsyncEvent", ".", "SockTxFailData", ".", "sd", ")", ";", "break", ";", "default", ":", "UART_PRINT", "(", "\"", "\"", "\"", "\\n", "\\n", "\"", ",", "pSock", "->", "socketAsyncEvent", ".", "SockTxFailData", ".", "sd", ",", "pSock", "->", "socketAsyncEvent", ".", "SockTxFailData", ".", "status", ")", ";", "break", ";", "}", "break", ";", "default", ":", "UART_PRINT", "(", "\"", "\\n", "\\n", "\"", ",", "pSock", "->", "Event", ")", ";", "break", ";", "}", "}" ]
This function handles socket events indication \param[in] pSock - Pointer to Socket Event Info
[ "This", "function", "handles", "socket", "events", "indication", "\\", "param", "[", "in", "]", "pSock", "-", "Pointer", "to", "Socket", "Event", "Info" ]
[ "// This application doesn't work w/ socket - Events are not expected\r" ]
[ { "param": "pSock", "type": "SlSockEvent_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pSock", "type": "SlSockEvent_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
37481b31bf5505f01a2369dc4c4e375d6a4cf5da
csylo/launchpad-tcp
lp2-tcp-receive-file/main.c
[ "BSD-3-Clause" ]
C
InitializeAppVariables
void
static void InitializeAppVariables() { g_ulStatus = 0; g_ulGatewayIP = 0; memset(g_ucConnectionSSID,0,sizeof(g_ucConnectionSSID)); memset(g_ucConnectionBSSID,0,sizeof(g_ucConnectionBSSID)); g_ulDestinationIp = IP_ADDR; g_uiPortNum = PORT_NUM; g_ulPacketCount = TCP_PACKET_COUNT; }
//***************************************************************************** // //! This function initializes the application variables //! //*****************************************************************************
This function initializes the application variables
[ "This", "function", "initializes", "the", "application", "variables" ]
static void InitializeAppVariables() { g_ulStatus = 0; g_ulGatewayIP = 0; memset(g_ucConnectionSSID,0,sizeof(g_ucConnectionSSID)); memset(g_ucConnectionBSSID,0,sizeof(g_ucConnectionBSSID)); g_ulDestinationIp = IP_ADDR; g_uiPortNum = PORT_NUM; g_ulPacketCount = TCP_PACKET_COUNT; }
[ "static", "void", "InitializeAppVariables", "(", ")", "{", "g_ulStatus", "=", "0", ";", "g_ulGatewayIP", "=", "0", ";", "memset", "(", "g_ucConnectionSSID", ",", "0", ",", "sizeof", "(", "g_ucConnectionSSID", ")", ")", ";", "memset", "(", "g_ucConnectionBSSID", ",", "0", ",", "sizeof", "(", "g_ucConnectionBSSID", ")", ")", ";", "g_ulDestinationIp", "=", "IP_ADDR", ";", "g_uiPortNum", "=", "PORT_NUM", ";", "g_ulPacketCount", "=", "TCP_PACKET_COUNT", ";", "}" ]
This function initializes the application variables
[ "This", "function", "initializes", "the", "application", "variables" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
37481b31bf5505f01a2369dc4c4e375d6a4cf5da
csylo/launchpad-tcp
lp2-tcp-receive-file/main.c
[ "BSD-3-Clause" ]
C
ConfigureSimpleLinkToDefaultState
null
static long ConfigureSimpleLinkToDefaultState() { SlVersionFull ver = {0}; _WlanRxFilterOperationCommandBuff_t RxFilterIdMask = {0}; unsigned char ucVal = 1; unsigned char ucConfigOpt = 0; unsigned char ucConfigLen = 0; unsigned char ucPower = 0; long lRetVal = -1; long lMode = -1; lMode = sl_Start(0, 0, 0); ASSERT_ON_ERROR(lMode); // If the device is not in station-mode, try configuring it in station-mode if (ROLE_STA != lMode) { if (ROLE_AP == lMode) { // If the device is in AP mode, we need to wait for this event // before doing anything while(!IS_IP_ACQUIRED(g_ulStatus)) { #ifndef SL_PLATFORM_MULTI_THREADED _SlNonOsMainLoopTask(); #endif } } // Switch to STA role and restart lRetVal = sl_WlanSetMode(ROLE_STA); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_Stop(0xFF); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_Start(0, 0, 0); ASSERT_ON_ERROR(lRetVal); // Check if the device is in station again if (ROLE_STA != lRetVal) { // We don't want to proceed if the device is not coming up in STA-mode return DEVICE_NOT_IN_STATION_MODE; } } // Get the device's version-information ucConfigOpt = SL_DEVICE_GENERAL_VERSION; ucConfigLen = sizeof(ver); lRetVal = sl_DevGet(SL_DEVICE_GENERAL_CONFIGURATION, &ucConfigOpt, &ucConfigLen, (unsigned char *)(&ver)); ASSERT_ON_ERROR(lRetVal); // Set connection policy to Auto + SmartConfig // (Device's default connection policy) lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1, 0, 0, 0, 1), NULL, 0); ASSERT_ON_ERROR(lRetVal); // Remove all profiles lRetVal = sl_WlanProfileDel(0xFF); ASSERT_ON_ERROR(lRetVal); // // Device in station-mode. Disconnect previous connection if any // The function returns 0 if 'Disconnected done', negative number if already // disconnected Wait for 'disconnection' event if 0 is returned, Ignore // other return-codes // lRetVal = sl_WlanDisconnect(); if(0 == lRetVal) { // Wait while(IS_CONNECTED(g_ulStatus)) { #ifndef SL_PLATFORM_MULTI_THREADED _SlNonOsMainLoopTask(); #endif } } // Enable DHCP client lRetVal = sl_NetCfgSet(SL_IPV4_STA_P2P_CL_DHCP_ENABLE,1,1,&ucVal); ASSERT_ON_ERROR(lRetVal); // Disable scan ucConfigOpt = SL_SCAN_POLICY(0); lRetVal = sl_WlanPolicySet(SL_POLICY_SCAN , ucConfigOpt, NULL, 0); ASSERT_ON_ERROR(lRetVal); // Set Tx power level for station mode // Number between 0-15, as dB offset from max power - 0 will set max power ucPower = 0; lRetVal = sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, WLAN_GENERAL_PARAM_OPT_STA_TX_POWER, 1, (unsigned char *)&ucPower); ASSERT_ON_ERROR(lRetVal); // Set PM policy to normal lRetVal = sl_WlanPolicySet(SL_POLICY_PM , SL_NORMAL_POLICY, NULL, 0); ASSERT_ON_ERROR(lRetVal); // Unregister mDNS services lRetVal = sl_NetAppMDNSUnRegisterService(0, 0); ASSERT_ON_ERROR(lRetVal); // Remove all 64 filters (8*8) memset(RxFilterIdMask.FilterIdMask, 0xFF, 8); lRetVal = sl_WlanRxFilterSet(SL_REMOVE_RX_FILTER, (_u8 *)&RxFilterIdMask, sizeof(_WlanRxFilterOperationCommandBuff_t)); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_Stop(SL_STOP_TIMEOUT); ASSERT_ON_ERROR(lRetVal); InitializeAppVariables(); return lRetVal; // Success }
//***************************************************************************** //! \brief This function puts the device in its default state. It: //! - Set the mode to STATION //! - Configures connection policy to Auto and AutoSmartConfig //! - Deletes all the stored profiles //! - Enables DHCP //! - Disables Scan policy //! - Sets Tx power to maximum //! - Sets power policy to normal //! - Unregister mDNS services //! - Remove all filters //! //! \param none //! \return On success, zero is returned. On error, negative is returned //*****************************************************************************
\brief This function puts the device in its default state. It: Set the mode to STATION Configures connection policy to Auto and AutoSmartConfig Deletes all the stored profiles Enables DHCP Disables Scan policy Sets Tx power to maximum Sets power policy to normal Unregister mDNS services Remove all filters \param none \return On success, zero is returned. On error, negative is returned
[ "\\", "brief", "This", "function", "puts", "the", "device", "in", "its", "default", "state", ".", "It", ":", "Set", "the", "mode", "to", "STATION", "Configures", "connection", "policy", "to", "Auto", "and", "AutoSmartConfig", "Deletes", "all", "the", "stored", "profiles", "Enables", "DHCP", "Disables", "Scan", "policy", "Sets", "Tx", "power", "to", "maximum", "Sets", "power", "policy", "to", "normal", "Unregister", "mDNS", "services", "Remove", "all", "filters", "\\", "param", "none", "\\", "return", "On", "success", "zero", "is", "returned", ".", "On", "error", "negative", "is", "returned" ]
static long ConfigureSimpleLinkToDefaultState() { SlVersionFull ver = {0}; _WlanRxFilterOperationCommandBuff_t RxFilterIdMask = {0}; unsigned char ucVal = 1; unsigned char ucConfigOpt = 0; unsigned char ucConfigLen = 0; unsigned char ucPower = 0; long lRetVal = -1; long lMode = -1; lMode = sl_Start(0, 0, 0); ASSERT_ON_ERROR(lMode); if (ROLE_STA != lMode) { if (ROLE_AP == lMode) { while(!IS_IP_ACQUIRED(g_ulStatus)) { #ifndef SL_PLATFORM_MULTI_THREADED _SlNonOsMainLoopTask(); #endif } } lRetVal = sl_WlanSetMode(ROLE_STA); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_Stop(0xFF); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_Start(0, 0, 0); ASSERT_ON_ERROR(lRetVal); if (ROLE_STA != lRetVal) { return DEVICE_NOT_IN_STATION_MODE; } } ucConfigOpt = SL_DEVICE_GENERAL_VERSION; ucConfigLen = sizeof(ver); lRetVal = sl_DevGet(SL_DEVICE_GENERAL_CONFIGURATION, &ucConfigOpt, &ucConfigLen, (unsigned char *)(&ver)); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1, 0, 0, 0, 1), NULL, 0); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_WlanProfileDel(0xFF); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_WlanDisconnect(); if(0 == lRetVal) { while(IS_CONNECTED(g_ulStatus)) { #ifndef SL_PLATFORM_MULTI_THREADED _SlNonOsMainLoopTask(); #endif } } lRetVal = sl_NetCfgSet(SL_IPV4_STA_P2P_CL_DHCP_ENABLE,1,1,&ucVal); ASSERT_ON_ERROR(lRetVal); ucConfigOpt = SL_SCAN_POLICY(0); lRetVal = sl_WlanPolicySet(SL_POLICY_SCAN , ucConfigOpt, NULL, 0); ASSERT_ON_ERROR(lRetVal); ucPower = 0; lRetVal = sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, WLAN_GENERAL_PARAM_OPT_STA_TX_POWER, 1, (unsigned char *)&ucPower); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_WlanPolicySet(SL_POLICY_PM , SL_NORMAL_POLICY, NULL, 0); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_NetAppMDNSUnRegisterService(0, 0); ASSERT_ON_ERROR(lRetVal); memset(RxFilterIdMask.FilterIdMask, 0xFF, 8); lRetVal = sl_WlanRxFilterSet(SL_REMOVE_RX_FILTER, (_u8 *)&RxFilterIdMask, sizeof(_WlanRxFilterOperationCommandBuff_t)); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_Stop(SL_STOP_TIMEOUT); ASSERT_ON_ERROR(lRetVal); InitializeAppVariables(); return lRetVal; }
[ "static", "long", "ConfigureSimpleLinkToDefaultState", "(", ")", "{", "SlVersionFull", "ver", "=", "{", "0", "}", ";", "_WlanRxFilterOperationCommandBuff_t", "RxFilterIdMask", "=", "{", "0", "}", ";", "unsigned", "char", "ucVal", "=", "1", ";", "unsigned", "char", "ucConfigOpt", "=", "0", ";", "unsigned", "char", "ucConfigLen", "=", "0", ";", "unsigned", "char", "ucPower", "=", "0", ";", "long", "lRetVal", "=", "-1", ";", "long", "lMode", "=", "-1", ";", "lMode", "=", "sl_Start", "(", "0", ",", "0", ",", "0", ")", ";", "ASSERT_ON_ERROR", "(", "lMode", ")", ";", "if", "(", "ROLE_STA", "!=", "lMode", ")", "{", "if", "(", "ROLE_AP", "==", "lMode", ")", "{", "while", "(", "!", "IS_IP_ACQUIRED", "(", "g_ulStatus", ")", ")", "{", "#ifndef", "SL_PLATFORM_MULTI_THREADED", "_SlNonOsMainLoopTask", "(", ")", ";", "#endif", "}", "}", "lRetVal", "=", "sl_WlanSetMode", "(", "ROLE_STA", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "lRetVal", "=", "sl_Stop", "(", "0xFF", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "lRetVal", "=", "sl_Start", "(", "0", ",", "0", ",", "0", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "if", "(", "ROLE_STA", "!=", "lRetVal", ")", "{", "return", "DEVICE_NOT_IN_STATION_MODE", ";", "}", "}", "ucConfigOpt", "=", "SL_DEVICE_GENERAL_VERSION", ";", "ucConfigLen", "=", "sizeof", "(", "ver", ")", ";", "lRetVal", "=", "sl_DevGet", "(", "SL_DEVICE_GENERAL_CONFIGURATION", ",", "&", "ucConfigOpt", ",", "&", "ucConfigLen", ",", "(", "unsigned", "char", "*", ")", "(", "&", "ver", ")", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "lRetVal", "=", "sl_WlanPolicySet", "(", "SL_POLICY_CONNECTION", ",", "SL_CONNECTION_POLICY", "(", "1", ",", "0", ",", "0", ",", "0", ",", "1", ")", ",", "NULL", ",", "0", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "lRetVal", "=", "sl_WlanProfileDel", "(", "0xFF", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "lRetVal", "=", "sl_WlanDisconnect", "(", ")", ";", "if", "(", "0", "==", "lRetVal", ")", "{", "while", "(", "IS_CONNECTED", "(", "g_ulStatus", ")", ")", "{", "#ifndef", "SL_PLATFORM_MULTI_THREADED", "_SlNonOsMainLoopTask", "(", ")", ";", "#endif", "}", "}", "lRetVal", "=", "sl_NetCfgSet", "(", "SL_IPV4_STA_P2P_CL_DHCP_ENABLE", ",", "1", ",", "1", ",", "&", "ucVal", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "ucConfigOpt", "=", "SL_SCAN_POLICY", "(", "0", ")", ";", "lRetVal", "=", "sl_WlanPolicySet", "(", "SL_POLICY_SCAN", ",", "ucConfigOpt", ",", "NULL", ",", "0", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "ucPower", "=", "0", ";", "lRetVal", "=", "sl_WlanSet", "(", "SL_WLAN_CFG_GENERAL_PARAM_ID", ",", "WLAN_GENERAL_PARAM_OPT_STA_TX_POWER", ",", "1", ",", "(", "unsigned", "char", "*", ")", "&", "ucPower", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "lRetVal", "=", "sl_WlanPolicySet", "(", "SL_POLICY_PM", ",", "SL_NORMAL_POLICY", ",", "NULL", ",", "0", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "lRetVal", "=", "sl_NetAppMDNSUnRegisterService", "(", "0", ",", "0", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "memset", "(", "RxFilterIdMask", ".", "FilterIdMask", ",", "0xFF", ",", "8", ")", ";", "lRetVal", "=", "sl_WlanRxFilterSet", "(", "SL_REMOVE_RX_FILTER", ",", "(", "_u8", "*", ")", "&", "RxFilterIdMask", ",", "sizeof", "(", "_WlanRxFilterOperationCommandBuff_t", ")", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "lRetVal", "=", "sl_Stop", "(", "SL_STOP_TIMEOUT", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "InitializeAppVariables", "(", ")", ";", "return", "lRetVal", ";", "}" ]
\brief This function puts the device in its default state.
[ "\\", "brief", "This", "function", "puts", "the", "device", "in", "its", "default", "state", "." ]
[ "// If the device is not in station-mode, try configuring it in station-mode \r", "// If the device is in AP mode, we need to wait for this event \r", "// before doing anything \r", "// Switch to STA role and restart \r", "// Check if the device is in station again \r", "// We don't want to proceed if the device is not coming up in STA-mode \r", "// Get the device's version-information\r", "// Set connection policy to Auto + SmartConfig \r", "// (Device's default connection policy)\r", "// Remove all profiles\r", "//\r", "// Device in station-mode. Disconnect previous connection if any\r", "// The function returns 0 if 'Disconnected done', negative number if already\r", "// disconnected Wait for 'disconnection' event if 0 is returned, Ignore \r", "// other return-codes\r", "//\r", "// Wait\r", "// Enable DHCP client\r", "// Disable scan\r", "// Set Tx power level for station mode\r", "// Number between 0-15, as dB offset from max power - 0 will set max power\r", "// Set PM policy to normal\r", "// Unregister mDNS services\r", "// Remove all 64 filters (8*8)\r", "// Success\r" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
37481b31bf5505f01a2369dc4c4e375d6a4cf5da
csylo/launchpad-tcp
lp2-tcp-receive-file/main.c
[ "BSD-3-Clause" ]
C
BsdTcpServer
int
int BsdTcpServer(unsigned short usPort) { SlSockAddrIn_t sAddr; int iAddrSize; int iSockID; int iStatus; int iTestBufLen = BUF_SIZE; int resetBufCount = 0; //File IO from: //http://www.multisilicon.com/_a/blog/a25365269~/group___file_system.html#ga6a9aaae1813255fa13c7d6bc26c2904c //Requires fs.h char* myFileName = "LP2_received_data.txt"; long myFileHandle = -1; //get's replaced long LP2_RetVal; //negative retval is an error unsigned long Offset = 0; //keep track of how much of the file has been sent // open file (create mode) LP2_RetVal = sl_FsOpen((unsigned char *) myFileName, FS_MODE_OPEN_CREATE(65536, _FS_FILE_OPEN_FLAG_NO_SIGNATURE_TEST | _FS_FILE_OPEN_FLAG_COMMIT ), NULL, &myFileHandle); //filling the TCP server socket address sAddr.sin_family = SL_AF_INET; sAddr.sin_port = sl_Htons((unsigned short)usPort); sAddr.sin_addr.s_addr = sl_Htonl((unsigned int)g_ulDestinationIp); iAddrSize = sizeof(SlSockAddrIn_t); // creating a TCP socket iSockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0); if( iSockID < 0 ){ ASSERT_ON_ERROR(SOCKET_CREATE_ERROR); } //connecting to TCP server iStatus = sl_Connect(iSockID, ( SlSockAddr_t *)&sAddr, iAddrSize); if( iStatus < 0 ){ // error sl_Close(iSockID); ASSERT_ON_ERROR(CONNECT_ERROR); } //Receiving packets from EC2 iStatus = 1024; Offset = 0; iStatus = sl_Recv(iSockID, g_cBsdBuf, iTestBufLen, 0); //returns # of bytes received UART_PRINT("\n\rReceived %d bytes\n\r", iStatus); LP2_RetVal = sl_FsWrite(myFileHandle, Offset, (unsigned char *) g_cBsdBuf, 1024); //Write g_cBsdBuf to file Offset += LP2_RetVal; if( iStatus <= 0 ){ // error sl_Close(iSockID); UART_PRINT("iStatus is %d\n\r", iStatus); ASSERT_ON_ERROR(RECV_ERROR); } for(resetBufCount = 0; resetBufCount<1024; resetBufCount++){ //clear g_cBsdBuf g_cBsdBuf[resetBufCount] = '\0'; } Report("Recieved %u packets successfully\n\n\n\n\n\n\n\r",g_ulPacketCount); //closing the socket after sending packets iStatus = sl_Close(iSockID); ASSERT_ON_ERROR(iStatus); // close file from write mode LP2_RetVal = sl_FsClose(myFileHandle, NULL, NULL , 0); // open file in read mode to print to console LP2_RetVal = sl_FsOpen((unsigned char *) myFileName, FS_MODE_OPEN_READ, NULL, &myFileHandle); Offset = 0; LP2_RetVal = 1024; while(LP2_RetVal == 1024){ int resetBufCount; LP2_RetVal = sl_FsRead(myFileHandle, Offset, (unsigned char *) g_cBsdBuf, 1024); Offset += 1024; UART_PRINT(g_cBsdBuf); for(resetBufCount = 0; resetBufCount<1024; resetBufCount++){ //clear g_cBsdBuf g_cBsdBuf[resetBufCount] = '\0'; } } return 0; //return 0 means success }
//**************************************************************************** //! Listens for a connection request from EC2 client, then receives data. //****************************************************************************
Listens for a connection request from EC2 client, then receives data.
[ "Listens", "for", "a", "connection", "request", "from", "EC2", "client", "then", "receives", "data", "." ]
int BsdTcpServer(unsigned short usPort) { SlSockAddrIn_t sAddr; int iAddrSize; int iSockID; int iStatus; int iTestBufLen = BUF_SIZE; int resetBufCount = 0; char* myFileName = "LP2_received_data.txt"; long myFileHandle = -1; long LP2_RetVal; unsigned long Offset = 0; LP2_RetVal = sl_FsOpen((unsigned char *) myFileName, FS_MODE_OPEN_CREATE(65536, _FS_FILE_OPEN_FLAG_NO_SIGNATURE_TEST | _FS_FILE_OPEN_FLAG_COMMIT ), NULL, &myFileHandle); sAddr.sin_family = SL_AF_INET; sAddr.sin_port = sl_Htons((unsigned short)usPort); sAddr.sin_addr.s_addr = sl_Htonl((unsigned int)g_ulDestinationIp); iAddrSize = sizeof(SlSockAddrIn_t); iSockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0); if( iSockID < 0 ){ ASSERT_ON_ERROR(SOCKET_CREATE_ERROR); } iStatus = sl_Connect(iSockID, ( SlSockAddr_t *)&sAddr, iAddrSize); if( iStatus < 0 ){ sl_Close(iSockID); ASSERT_ON_ERROR(CONNECT_ERROR); } iStatus = 1024; Offset = 0; iStatus = sl_Recv(iSockID, g_cBsdBuf, iTestBufLen, 0); UART_PRINT("\n\rReceived %d bytes\n\r", iStatus); LP2_RetVal = sl_FsWrite(myFileHandle, Offset, (unsigned char *) g_cBsdBuf, 1024); Offset += LP2_RetVal; if( iStatus <= 0 ){ sl_Close(iSockID); UART_PRINT("iStatus is %d\n\r", iStatus); ASSERT_ON_ERROR(RECV_ERROR); } for(resetBufCount = 0; resetBufCount<1024; resetBufCount++){ g_cBsdBuf[resetBufCount] = '\0'; } Report("Recieved %u packets successfully\n\n\n\n\n\n\n\r",g_ulPacketCount); iStatus = sl_Close(iSockID); ASSERT_ON_ERROR(iStatus); LP2_RetVal = sl_FsClose(myFileHandle, NULL, NULL , 0); LP2_RetVal = sl_FsOpen((unsigned char *) myFileName, FS_MODE_OPEN_READ, NULL, &myFileHandle); Offset = 0; LP2_RetVal = 1024; while(LP2_RetVal == 1024){ int resetBufCount; LP2_RetVal = sl_FsRead(myFileHandle, Offset, (unsigned char *) g_cBsdBuf, 1024); Offset += 1024; UART_PRINT(g_cBsdBuf); for(resetBufCount = 0; resetBufCount<1024; resetBufCount++){ g_cBsdBuf[resetBufCount] = '\0'; } } return 0; }
[ "int", "BsdTcpServer", "(", "unsigned", "short", "usPort", ")", "{", "SlSockAddrIn_t", "sAddr", ";", "int", "iAddrSize", ";", "int", "iSockID", ";", "int", "iStatus", ";", "int", "iTestBufLen", "=", "BUF_SIZE", ";", "int", "resetBufCount", "=", "0", ";", "char", "*", "myFileName", "=", "\"", "\"", ";", "long", "myFileHandle", "=", "-1", ";", "long", "LP2_RetVal", ";", "unsigned", "long", "Offset", "=", "0", ";", "LP2_RetVal", "=", "sl_FsOpen", "(", "(", "unsigned", "char", "*", ")", "myFileName", ",", "FS_MODE_OPEN_CREATE", "(", "65536", ",", "_FS_FILE_OPEN_FLAG_NO_SIGNATURE_TEST", "|", "_FS_FILE_OPEN_FLAG_COMMIT", ")", ",", "NULL", ",", "&", "myFileHandle", ")", ";", "sAddr", ".", "sin_family", "=", "SL_AF_INET", ";", "sAddr", ".", "sin_port", "=", "sl_Htons", "(", "(", "unsigned", "short", ")", "usPort", ")", ";", "sAddr", ".", "sin_addr", ".", "s_addr", "=", "sl_Htonl", "(", "(", "unsigned", "int", ")", "g_ulDestinationIp", ")", ";", "iAddrSize", "=", "sizeof", "(", "SlSockAddrIn_t", ")", ";", "iSockID", "=", "sl_Socket", "(", "SL_AF_INET", ",", "SL_SOCK_STREAM", ",", "0", ")", ";", "if", "(", "iSockID", "<", "0", ")", "{", "ASSERT_ON_ERROR", "(", "SOCKET_CREATE_ERROR", ")", ";", "}", "iStatus", "=", "sl_Connect", "(", "iSockID", ",", "(", "SlSockAddr_t", "*", ")", "&", "sAddr", ",", "iAddrSize", ")", ";", "if", "(", "iStatus", "<", "0", ")", "{", "sl_Close", "(", "iSockID", ")", ";", "ASSERT_ON_ERROR", "(", "CONNECT_ERROR", ")", ";", "}", "iStatus", "=", "1024", ";", "Offset", "=", "0", ";", "iStatus", "=", "sl_Recv", "(", "iSockID", ",", "g_cBsdBuf", ",", "iTestBufLen", ",", "0", ")", ";", "UART_PRINT", "(", "\"", "\\n", "\\r", "\\n", "\\r", "\"", ",", "iStatus", ")", ";", "LP2_RetVal", "=", "sl_FsWrite", "(", "myFileHandle", ",", "Offset", ",", "(", "unsigned", "char", "*", ")", "g_cBsdBuf", ",", "1024", ")", ";", "Offset", "+=", "LP2_RetVal", ";", "if", "(", "iStatus", "<=", "0", ")", "{", "sl_Close", "(", "iSockID", ")", ";", "UART_PRINT", "(", "\"", "\\n", "\\r", "\"", ",", "iStatus", ")", ";", "ASSERT_ON_ERROR", "(", "RECV_ERROR", ")", ";", "}", "for", "(", "resetBufCount", "=", "0", ";", "resetBufCount", "<", "1024", ";", "resetBufCount", "++", ")", "{", "g_cBsdBuf", "[", "resetBufCount", "]", "=", "'", "\\0", "'", ";", "}", "Report", "(", "\"", "\\n", "\\n", "\\n", "\\n", "\\n", "\\n", "\\n", "\\r", "\"", ",", "g_ulPacketCount", ")", ";", "iStatus", "=", "sl_Close", "(", "iSockID", ")", ";", "ASSERT_ON_ERROR", "(", "iStatus", ")", ";", "LP2_RetVal", "=", "sl_FsClose", "(", "myFileHandle", ",", "NULL", ",", "NULL", ",", "0", ")", ";", "LP2_RetVal", "=", "sl_FsOpen", "(", "(", "unsigned", "char", "*", ")", "myFileName", ",", "FS_MODE_OPEN_READ", ",", "NULL", ",", "&", "myFileHandle", ")", ";", "Offset", "=", "0", ";", "LP2_RetVal", "=", "1024", ";", "while", "(", "LP2_RetVal", "==", "1024", ")", "{", "int", "resetBufCount", ";", "LP2_RetVal", "=", "sl_FsRead", "(", "myFileHandle", ",", "Offset", ",", "(", "unsigned", "char", "*", ")", "g_cBsdBuf", ",", "1024", ")", ";", "Offset", "+=", "1024", ";", "UART_PRINT", "(", "g_cBsdBuf", ")", ";", "for", "(", "resetBufCount", "=", "0", ";", "resetBufCount", "<", "1024", ";", "resetBufCount", "++", ")", "{", "g_cBsdBuf", "[", "resetBufCount", "]", "=", "'", "\\0", "'", ";", "}", "}", "return", "0", ";", "}" ]
Listens for a connection request from EC2 client, then receives data.
[ "Listens", "for", "a", "connection", "request", "from", "EC2", "client", "then", "receives", "data", "." ]
[ "//File IO from:\r", "//http://www.multisilicon.com/_a/blog/a25365269~/group___file_system.html#ga6a9aaae1813255fa13c7d6bc26c2904c\r", "//Requires fs.h\r", "//get's replaced\r", "//negative retval is an error\r", "//keep track of how much of the file has been sent\r", "// open file (create mode)\r", "//filling the TCP server socket address\r", "// creating a TCP socket\r", "//connecting to TCP server\r", "// error\r", "//Receiving packets from EC2\r", "//returns # of bytes received\r", "//Write g_cBsdBuf to file\r", "// error\r", "//clear g_cBsdBuf\r", "//closing the socket after sending packets\r", "// close file from write mode\r", "// open file in read mode to print to console\r", "//clear g_cBsdBuf\r", "//return 0 means success\r" ]
[ { "param": "usPort", "type": "unsigned short" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "usPort", "type": "unsigned short", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
37481b31bf5505f01a2369dc4c4e375d6a4cf5da
csylo/launchpad-tcp
lp2-tcp-receive-file/main.c
[ "BSD-3-Clause" ]
C
WlanConnect
null
static long WlanConnect() { SlSecParams_t secParams = {0}; long lRetVal = 0; secParams.Key = (signed char*)SECURITY_KEY; secParams.KeyLen = strlen(SECURITY_KEY); secParams.Type = SECURITY_TYPE; lRetVal = sl_WlanConnect((signed char*)SSID_NAME, strlen(SSID_NAME), 0, &secParams, 0); ASSERT_ON_ERROR(lRetVal); /* Wait */ while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus))) { // Wait for WLAN Event #ifndef SL_PLATFORM_MULTI_THREADED _SlNonOsMainLoopTask(); #endif } return SUCCESS; }
//**************************************************************************** // //! \brief Connecting to a WLAN Accesspoint //! //! This function connects to the required AP (SSID_NAME) with Security //! parameters specified in te form of macros at the top of this file //! //! \param[in] None //! //! \return Status value //! //! \warning If the WLAN connection fails or we don't aquire an IP //! address, It will be stuck in this function forever. // //****************************************************************************
\brief Connecting to a WLAN Accesspoint This function connects to the required AP (SSID_NAME) with Security parameters specified in te form of macros at the top of this file \param[in] None \return Status value \warning If the WLAN connection fails or we don't aquire an IP address, It will be stuck in this function forever.
[ "\\", "brief", "Connecting", "to", "a", "WLAN", "Accesspoint", "This", "function", "connects", "to", "the", "required", "AP", "(", "SSID_NAME", ")", "with", "Security", "parameters", "specified", "in", "te", "form", "of", "macros", "at", "the", "top", "of", "this", "file", "\\", "param", "[", "in", "]", "None", "\\", "return", "Status", "value", "\\", "warning", "If", "the", "WLAN", "connection", "fails", "or", "we", "don", "'", "t", "aquire", "an", "IP", "address", "It", "will", "be", "stuck", "in", "this", "function", "forever", "." ]
static long WlanConnect() { SlSecParams_t secParams = {0}; long lRetVal = 0; secParams.Key = (signed char*)SECURITY_KEY; secParams.KeyLen = strlen(SECURITY_KEY); secParams.Type = SECURITY_TYPE; lRetVal = sl_WlanConnect((signed char*)SSID_NAME, strlen(SSID_NAME), 0, &secParams, 0); ASSERT_ON_ERROR(lRetVal); while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus))) { #ifndef SL_PLATFORM_MULTI_THREADED _SlNonOsMainLoopTask(); #endif } return SUCCESS; }
[ "static", "long", "WlanConnect", "(", ")", "{", "SlSecParams_t", "secParams", "=", "{", "0", "}", ";", "long", "lRetVal", "=", "0", ";", "secParams", ".", "Key", "=", "(", "signed", "char", "*", ")", "SECURITY_KEY", ";", "secParams", ".", "KeyLen", "=", "strlen", "(", "SECURITY_KEY", ")", ";", "secParams", ".", "Type", "=", "SECURITY_TYPE", ";", "lRetVal", "=", "sl_WlanConnect", "(", "(", "signed", "char", "*", ")", "SSID_NAME", ",", "strlen", "(", "SSID_NAME", ")", ",", "0", ",", "&", "secParams", ",", "0", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "while", "(", "(", "!", "IS_CONNECTED", "(", "g_ulStatus", ")", ")", "||", "(", "!", "IS_IP_ACQUIRED", "(", "g_ulStatus", ")", ")", ")", "{", "#ifndef", "SL_PLATFORM_MULTI_THREADED", "_SlNonOsMainLoopTask", "(", ")", ";", "#endif", "}", "return", "SUCCESS", ";", "}" ]
\brief Connecting to a WLAN Accesspoint This function connects to the required AP (SSID_NAME) with Security parameters specified in te form of macros at the top of this file
[ "\\", "brief", "Connecting", "to", "a", "WLAN", "Accesspoint", "This", "function", "connects", "to", "the", "required", "AP", "(", "SSID_NAME", ")", "with", "Security", "parameters", "specified", "in", "te", "form", "of", "macros", "at", "the", "top", "of", "this", "file" ]
[ "/* Wait */", "// Wait for WLAN Event\r" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
485ffb2c4fe3fb44322d9dd98058e32e7b0e5d45
csylo/launchpad-tcp
lp1-tcp-send-file/main.c
[ "BSD-3-Clause" ]
C
SimpleLinkWlanEventHandler
void
void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent) { if(!pWlanEvent) { return; } switch(pWlanEvent->Event) { case SL_WLAN_CONNECT_EVENT: { SET_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION); // // Information about the connected AP (like name, MAC etc) will be // available in 'slWlanConnectAsyncResponse_t'-Applications // can use it if required // // slWlanConnectAsyncResponse_t *pEventData = NULL; // pEventData = &pWlanEvent->EventData.STAandP2PModeWlanConnected; // // Copy new connection SSID and BSSID to global parameters memcpy(g_ucConnectionSSID,pWlanEvent->EventData. STAandP2PModeWlanConnected.ssid_name, pWlanEvent->EventData.STAandP2PModeWlanConnected.ssid_len); memcpy(g_ucConnectionBSSID, pWlanEvent->EventData.STAandP2PModeWlanConnected.bssid, SL_BSSID_LENGTH); UART_PRINT("[WLAN EVENT] STA Connected to the AP: %s ," " BSSID: %x:%x:%x:%x:%x:%x\n\r", g_ucConnectionSSID,g_ucConnectionBSSID[0], g_ucConnectionBSSID[1],g_ucConnectionBSSID[2], g_ucConnectionBSSID[3],g_ucConnectionBSSID[4], g_ucConnectionBSSID[5]); } break; case SL_WLAN_DISCONNECT_EVENT: { slWlanConnectAsyncResponse_t* pEventData = NULL; CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION); CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED); pEventData = &pWlanEvent->EventData.STAandP2PModeDisconnected; // If the user has initiated 'Disconnect' request, //'reason_code' is SL_USER_INITIATED_DISCONNECTION if(SL_USER_INITIATED_DISCONNECTION == pEventData->reason_code) { UART_PRINT("[WLAN EVENT]Device disconnected from the AP: %s," "BSSID: %x:%x:%x:%x:%x:%x on application's request \n\r", g_ucConnectionSSID,g_ucConnectionBSSID[0], g_ucConnectionBSSID[1],g_ucConnectionBSSID[2], g_ucConnectionBSSID[3],g_ucConnectionBSSID[4], g_ucConnectionBSSID[5]); } else { UART_PRINT("[WLAN ERROR]Device disconnected from the AP AP: %s," "BSSID: %x:%x:%x:%x:%x:%x on an ERROR..!! \n\r", g_ucConnectionSSID,g_ucConnectionBSSID[0], g_ucConnectionBSSID[1],g_ucConnectionBSSID[2], g_ucConnectionBSSID[3],g_ucConnectionBSSID[4], g_ucConnectionBSSID[5]); } memset(g_ucConnectionSSID,0,sizeof(g_ucConnectionSSID)); memset(g_ucConnectionBSSID,0,sizeof(g_ucConnectionBSSID)); } break; default: { UART_PRINT("[WLAN EVENT] Unexpected event [0x%x]\n\r", pWlanEvent->Event); } break; } }
//***************************************************************************** // //! \brief The Function Handles WLAN Events //! //! \param[in] pWlanEvent - Pointer to WLAN Event Info //! //! \return None //! //*****************************************************************************
\brief The Function Handles WLAN Events \param[in] pWlanEvent - Pointer to WLAN Event Info \return None
[ "\\", "brief", "The", "Function", "Handles", "WLAN", "Events", "\\", "param", "[", "in", "]", "pWlanEvent", "-", "Pointer", "to", "WLAN", "Event", "Info", "\\", "return", "None" ]
void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent) { if(!pWlanEvent) { return; } switch(pWlanEvent->Event) { case SL_WLAN_CONNECT_EVENT: { SET_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION); memcpy(g_ucConnectionSSID,pWlanEvent->EventData. STAandP2PModeWlanConnected.ssid_name, pWlanEvent->EventData.STAandP2PModeWlanConnected.ssid_len); memcpy(g_ucConnectionBSSID, pWlanEvent->EventData.STAandP2PModeWlanConnected.bssid, SL_BSSID_LENGTH); UART_PRINT("[WLAN EVENT] STA Connected to the AP: %s ," " BSSID: %x:%x:%x:%x:%x:%x\n\r", g_ucConnectionSSID,g_ucConnectionBSSID[0], g_ucConnectionBSSID[1],g_ucConnectionBSSID[2], g_ucConnectionBSSID[3],g_ucConnectionBSSID[4], g_ucConnectionBSSID[5]); } break; case SL_WLAN_DISCONNECT_EVENT: { slWlanConnectAsyncResponse_t* pEventData = NULL; CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION); CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED); pEventData = &pWlanEvent->EventData.STAandP2PModeDisconnected; if(SL_USER_INITIATED_DISCONNECTION == pEventData->reason_code) { UART_PRINT("[WLAN EVENT]Device disconnected from the AP: %s," "BSSID: %x:%x:%x:%x:%x:%x on application's request \n\r", g_ucConnectionSSID,g_ucConnectionBSSID[0], g_ucConnectionBSSID[1],g_ucConnectionBSSID[2], g_ucConnectionBSSID[3],g_ucConnectionBSSID[4], g_ucConnectionBSSID[5]); } else { UART_PRINT("[WLAN ERROR]Device disconnected from the AP AP: %s," "BSSID: %x:%x:%x:%x:%x:%x on an ERROR..!! \n\r", g_ucConnectionSSID,g_ucConnectionBSSID[0], g_ucConnectionBSSID[1],g_ucConnectionBSSID[2], g_ucConnectionBSSID[3],g_ucConnectionBSSID[4], g_ucConnectionBSSID[5]); } memset(g_ucConnectionSSID,0,sizeof(g_ucConnectionSSID)); memset(g_ucConnectionBSSID,0,sizeof(g_ucConnectionBSSID)); } break; default: { UART_PRINT("[WLAN EVENT] Unexpected event [0x%x]\n\r", pWlanEvent->Event); } break; } }
[ "void", "SimpleLinkWlanEventHandler", "(", "SlWlanEvent_t", "*", "pWlanEvent", ")", "{", "if", "(", "!", "pWlanEvent", ")", "{", "return", ";", "}", "switch", "(", "pWlanEvent", "->", "Event", ")", "{", "case", "SL_WLAN_CONNECT_EVENT", ":", "{", "SET_STATUS_BIT", "(", "g_ulStatus", ",", "STATUS_BIT_CONNECTION", ")", ";", "memcpy", "(", "g_ucConnectionSSID", ",", "pWlanEvent", "->", "EventData", ".", "STAandP2PModeWlanConnected", ".", "ssid_name", ",", "pWlanEvent", "->", "EventData", ".", "STAandP2PModeWlanConnected", ".", "ssid_len", ")", ";", "memcpy", "(", "g_ucConnectionBSSID", ",", "pWlanEvent", "->", "EventData", ".", "STAandP2PModeWlanConnected", ".", "bssid", ",", "SL_BSSID_LENGTH", ")", ";", "UART_PRINT", "(", "\"", "\"", "\"", "\\n", "\\r", "\"", ",", "g_ucConnectionSSID", ",", "g_ucConnectionBSSID", "[", "0", "]", ",", "g_ucConnectionBSSID", "[", "1", "]", ",", "g_ucConnectionBSSID", "[", "2", "]", ",", "g_ucConnectionBSSID", "[", "3", "]", ",", "g_ucConnectionBSSID", "[", "4", "]", ",", "g_ucConnectionBSSID", "[", "5", "]", ")", ";", "}", "break", ";", "case", "SL_WLAN_DISCONNECT_EVENT", ":", "{", "slWlanConnectAsyncResponse_t", "*", "pEventData", "=", "NULL", ";", "CLR_STATUS_BIT", "(", "g_ulStatus", ",", "STATUS_BIT_CONNECTION", ")", ";", "CLR_STATUS_BIT", "(", "g_ulStatus", ",", "STATUS_BIT_IP_AQUIRED", ")", ";", "pEventData", "=", "&", "pWlanEvent", "->", "EventData", ".", "STAandP2PModeDisconnected", ";", "if", "(", "SL_USER_INITIATED_DISCONNECTION", "==", "pEventData", "->", "reason_code", ")", "{", "UART_PRINT", "(", "\"", "\"", "\"", "\\n", "\\r", "\"", ",", "g_ucConnectionSSID", ",", "g_ucConnectionBSSID", "[", "0", "]", ",", "g_ucConnectionBSSID", "[", "1", "]", ",", "g_ucConnectionBSSID", "[", "2", "]", ",", "g_ucConnectionBSSID", "[", "3", "]", ",", "g_ucConnectionBSSID", "[", "4", "]", ",", "g_ucConnectionBSSID", "[", "5", "]", ")", ";", "}", "else", "{", "UART_PRINT", "(", "\"", "\"", "\"", "\\n", "\\r", "\"", ",", "g_ucConnectionSSID", ",", "g_ucConnectionBSSID", "[", "0", "]", ",", "g_ucConnectionBSSID", "[", "1", "]", ",", "g_ucConnectionBSSID", "[", "2", "]", ",", "g_ucConnectionBSSID", "[", "3", "]", ",", "g_ucConnectionBSSID", "[", "4", "]", ",", "g_ucConnectionBSSID", "[", "5", "]", ")", ";", "}", "memset", "(", "g_ucConnectionSSID", ",", "0", ",", "sizeof", "(", "g_ucConnectionSSID", ")", ")", ";", "memset", "(", "g_ucConnectionBSSID", ",", "0", ",", "sizeof", "(", "g_ucConnectionBSSID", ")", ")", ";", "}", "break", ";", "default", ":", "{", "UART_PRINT", "(", "\"", "\\n", "\\r", "\"", ",", "pWlanEvent", "->", "Event", ")", ";", "}", "break", ";", "}", "}" ]
\brief The Function Handles WLAN Events \param[in] pWlanEvent - Pointer to WLAN Event Info
[ "\\", "brief", "The", "Function", "Handles", "WLAN", "Events", "\\", "param", "[", "in", "]", "pWlanEvent", "-", "Pointer", "to", "WLAN", "Event", "Info" ]
[ "//\r", "// Information about the connected AP (like name, MAC etc) will be\r", "// available in 'slWlanConnectAsyncResponse_t'-Applications\r", "// can use it if required\r", "//\r", "// slWlanConnectAsyncResponse_t *pEventData = NULL;\r", "// pEventData = &pWlanEvent->EventData.STAandP2PModeWlanConnected;\r", "//\r", "// Copy new connection SSID and BSSID to global parameters\r", "// If the user has initiated 'Disconnect' request,\r", "//'reason_code' is SL_USER_INITIATED_DISCONNECTION\r" ]
[ { "param": "pWlanEvent", "type": "SlWlanEvent_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pWlanEvent", "type": "SlWlanEvent_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
485ffb2c4fe3fb44322d9dd98058e32e7b0e5d45
csylo/launchpad-tcp
lp1-tcp-send-file/main.c
[ "BSD-3-Clause" ]
C
SimpleLinkNetAppEventHandler
void
void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent) { if(!pNetAppEvent) { return; } switch(pNetAppEvent->Event) { case SL_NETAPP_IPV4_IPACQUIRED_EVENT: { SlIpV4AcquiredAsync_t *pEventData = NULL; SET_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED); //Ip Acquired Event Data pEventData = &pNetAppEvent->EventData.ipAcquiredV4; g_ulIpAddr = pEventData->ip; //Gateway IP address g_ulGatewayIP = pEventData->gateway; UART_PRINT("[NETAPP EVENT] IP Acquired: IP=%d.%d.%d.%d , " "Gateway=%d.%d.%d.%d\n\r", SL_IPV4_BYTE(g_ulIpAddr,3), SL_IPV4_BYTE(g_ulIpAddr,2), SL_IPV4_BYTE(g_ulIpAddr,1), SL_IPV4_BYTE(g_ulIpAddr,0), SL_IPV4_BYTE(g_ulGatewayIP,3), SL_IPV4_BYTE(g_ulGatewayIP,2), SL_IPV4_BYTE(g_ulGatewayIP,1), SL_IPV4_BYTE(g_ulGatewayIP,0)); } break; default: { UART_PRINT("[NETAPP EVENT] Unexpected event [0x%x] \n\r", pNetAppEvent->Event); } break; } }
//***************************************************************************** // //! \brief This function handles network events such as IP acquisition, IP //! leased, IP released etc. //! //*****************************************************************************
\brief This function handles network events such as IP acquisition, IP leased, IP released etc.
[ "\\", "brief", "This", "function", "handles", "network", "events", "such", "as", "IP", "acquisition", "IP", "leased", "IP", "released", "etc", "." ]
void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent) { if(!pNetAppEvent) { return; } switch(pNetAppEvent->Event) { case SL_NETAPP_IPV4_IPACQUIRED_EVENT: { SlIpV4AcquiredAsync_t *pEventData = NULL; SET_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED); pEventData = &pNetAppEvent->EventData.ipAcquiredV4; g_ulIpAddr = pEventData->ip; g_ulGatewayIP = pEventData->gateway; UART_PRINT("[NETAPP EVENT] IP Acquired: IP=%d.%d.%d.%d , " "Gateway=%d.%d.%d.%d\n\r", SL_IPV4_BYTE(g_ulIpAddr,3), SL_IPV4_BYTE(g_ulIpAddr,2), SL_IPV4_BYTE(g_ulIpAddr,1), SL_IPV4_BYTE(g_ulIpAddr,0), SL_IPV4_BYTE(g_ulGatewayIP,3), SL_IPV4_BYTE(g_ulGatewayIP,2), SL_IPV4_BYTE(g_ulGatewayIP,1), SL_IPV4_BYTE(g_ulGatewayIP,0)); } break; default: { UART_PRINT("[NETAPP EVENT] Unexpected event [0x%x] \n\r", pNetAppEvent->Event); } break; } }
[ "void", "SimpleLinkNetAppEventHandler", "(", "SlNetAppEvent_t", "*", "pNetAppEvent", ")", "{", "if", "(", "!", "pNetAppEvent", ")", "{", "return", ";", "}", "switch", "(", "pNetAppEvent", "->", "Event", ")", "{", "case", "SL_NETAPP_IPV4_IPACQUIRED_EVENT", ":", "{", "SlIpV4AcquiredAsync_t", "*", "pEventData", "=", "NULL", ";", "SET_STATUS_BIT", "(", "g_ulStatus", ",", "STATUS_BIT_IP_AQUIRED", ")", ";", "pEventData", "=", "&", "pNetAppEvent", "->", "EventData", ".", "ipAcquiredV4", ";", "g_ulIpAddr", "=", "pEventData", "->", "ip", ";", "g_ulGatewayIP", "=", "pEventData", "->", "gateway", ";", "UART_PRINT", "(", "\"", "\"", "\"", "\\n", "\\r", "\"", ",", "SL_IPV4_BYTE", "(", "g_ulIpAddr", ",", "3", ")", ",", "SL_IPV4_BYTE", "(", "g_ulIpAddr", ",", "2", ")", ",", "SL_IPV4_BYTE", "(", "g_ulIpAddr", ",", "1", ")", ",", "SL_IPV4_BYTE", "(", "g_ulIpAddr", ",", "0", ")", ",", "SL_IPV4_BYTE", "(", "g_ulGatewayIP", ",", "3", ")", ",", "SL_IPV4_BYTE", "(", "g_ulGatewayIP", ",", "2", ")", ",", "SL_IPV4_BYTE", "(", "g_ulGatewayIP", ",", "1", ")", ",", "SL_IPV4_BYTE", "(", "g_ulGatewayIP", ",", "0", ")", ")", ";", "}", "break", ";", "default", ":", "{", "UART_PRINT", "(", "\"", "\\n", "\\r", "\"", ",", "pNetAppEvent", "->", "Event", ")", ";", "}", "break", ";", "}", "}" ]
\brief This function handles network events such as IP acquisition, IP leased, IP released etc.
[ "\\", "brief", "This", "function", "handles", "network", "events", "such", "as", "IP", "acquisition", "IP", "leased", "IP", "released", "etc", "." ]
[ "//Ip Acquired Event Data\r", "//Gateway IP address\r" ]
[ { "param": "pNetAppEvent", "type": "SlNetAppEvent_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pNetAppEvent", "type": "SlNetAppEvent_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
485ffb2c4fe3fb44322d9dd98058e32e7b0e5d45
csylo/launchpad-tcp
lp1-tcp-send-file/main.c
[ "BSD-3-Clause" ]
C
ConfigureSimpleLinkToDefaultState
null
static long ConfigureSimpleLinkToDefaultState(){ SlVersionFull ver = {0}; _WlanRxFilterOperationCommandBuff_t RxFilterIdMask = {0}; unsigned char ucVal = 1; unsigned char ucConfigOpt = 0; unsigned char ucConfigLen = 0; unsigned char ucPower = 0; long lRetVal = -1; long lMode = -1; lMode = sl_Start(0, 0, 0); ASSERT_ON_ERROR(lMode); // If the device is not in station-mode, try configuring it in station-mode if (ROLE_STA != lMode) { if (ROLE_AP == lMode) { // If the device is in AP mode, we need to wait for this event // before doing anything while(!IS_IP_ACQUIRED(g_ulStatus)) { #ifndef SL_PLATFORM_MULTI_THREADED _SlNonOsMainLoopTask(); #endif } } // Switch to STA role and restart lRetVal = sl_WlanSetMode(ROLE_STA); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_Stop(0xFF); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_Start(0, 0, 0); ASSERT_ON_ERROR(lRetVal); // Check if the device is in station again if (ROLE_STA != lRetVal) { // We don't want to proceed if the device is not coming up in STA-mode return DEVICE_NOT_IN_STATION_MODE; } } // Get the device's version-information ucConfigOpt = SL_DEVICE_GENERAL_VERSION; ucConfigLen = sizeof(ver); lRetVal = sl_DevGet(SL_DEVICE_GENERAL_CONFIGURATION, &ucConfigOpt, &ucConfigLen, (unsigned char *)(&ver)); ASSERT_ON_ERROR(lRetVal); UART_PRINT("Host Driver Version: %s\n\r",SL_DRIVER_VERSION); UART_PRINT("Build Version %d.%d.%d.%d.31.%d.%d.%d.%d.%d.%d.%d.%d\n\r", ver.NwpVersion[0],ver.NwpVersion[1],ver.NwpVersion[2],ver.NwpVersion[3], ver.ChipFwAndPhyVersion.FwVersion[0],ver.ChipFwAndPhyVersion.FwVersion[1], ver.ChipFwAndPhyVersion.FwVersion[2],ver.ChipFwAndPhyVersion.FwVersion[3], ver.ChipFwAndPhyVersion.PhyVersion[0],ver.ChipFwAndPhyVersion.PhyVersion[1], ver.ChipFwAndPhyVersion.PhyVersion[2],ver.ChipFwAndPhyVersion.PhyVersion[3]); // Set connection policy to Auto + SmartConfig // (Device's default connection policy) lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1, 0, 0, 0, 1), NULL, 0); ASSERT_ON_ERROR(lRetVal); // Remove all profiles lRetVal = sl_WlanProfileDel(0xFF); ASSERT_ON_ERROR(lRetVal); // // Device in station-mode. Disconnect previous connection if any // The function returns 0 if 'Disconnected done', negative number if already // disconnected Wait for 'disconnection' event if 0 is returned, Ignore // other return-codes // lRetVal = sl_WlanDisconnect(); if(0 == lRetVal) { // Wait while(IS_CONNECTED(g_ulStatus)) { #ifndef SL_PLATFORM_MULTI_THREADED _SlNonOsMainLoopTask(); #endif } } // Enable DHCP client lRetVal = sl_NetCfgSet(SL_IPV4_STA_P2P_CL_DHCP_ENABLE,1,1,&ucVal); ASSERT_ON_ERROR(lRetVal); // Disable scan ucConfigOpt = SL_SCAN_POLICY(0); lRetVal = sl_WlanPolicySet(SL_POLICY_SCAN , ucConfigOpt, NULL, 0); ASSERT_ON_ERROR(lRetVal); // Set Tx power level for station mode // Number between 0-15, as dB offset from max power - 0 will set max power ucPower = 0; lRetVal = sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, WLAN_GENERAL_PARAM_OPT_STA_TX_POWER, 1, (unsigned char *)&ucPower); ASSERT_ON_ERROR(lRetVal); // Set PM policy to normal lRetVal = sl_WlanPolicySet(SL_POLICY_PM , SL_NORMAL_POLICY, NULL, 0); ASSERT_ON_ERROR(lRetVal); // Unregister mDNS services lRetVal = sl_NetAppMDNSUnRegisterService(0, 0); ASSERT_ON_ERROR(lRetVal); // Remove all 64 filters (8*8) memset(RxFilterIdMask.FilterIdMask, 0xFF, 8); lRetVal = sl_WlanRxFilterSet(SL_REMOVE_RX_FILTER, (_u8 *)&RxFilterIdMask, sizeof(_WlanRxFilterOperationCommandBuff_t)); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_Stop(SL_STOP_TIMEOUT); ASSERT_ON_ERROR(lRetVal); InitializeAppVariables(); return lRetVal; // Success }
//***************************************************************************** //! \brief This function puts the device in its default state. It: //! - Set the mode to STATION //! - Configures connection policy to Auto and AutoSmartConfig //! - Deletes all the stored profiles //! - Enables DHCP //! - Disables Scan policy //! - Sets Tx power to maximum //! - Sets power policy to normal //! - Unregister mDNS services //! - Remove all filters //! //! \param none //! \return On success, zero is returned. On error, negative is returned //*****************************************************************************
\brief This function puts the device in its default state. It: Set the mode to STATION Configures connection policy to Auto and AutoSmartConfig Deletes all the stored profiles Enables DHCP Disables Scan policy Sets Tx power to maximum Sets power policy to normal Unregister mDNS services Remove all filters \param none \return On success, zero is returned. On error, negative is returned
[ "\\", "brief", "This", "function", "puts", "the", "device", "in", "its", "default", "state", ".", "It", ":", "Set", "the", "mode", "to", "STATION", "Configures", "connection", "policy", "to", "Auto", "and", "AutoSmartConfig", "Deletes", "all", "the", "stored", "profiles", "Enables", "DHCP", "Disables", "Scan", "policy", "Sets", "Tx", "power", "to", "maximum", "Sets", "power", "policy", "to", "normal", "Unregister", "mDNS", "services", "Remove", "all", "filters", "\\", "param", "none", "\\", "return", "On", "success", "zero", "is", "returned", ".", "On", "error", "negative", "is", "returned" ]
static long ConfigureSimpleLinkToDefaultState(){ SlVersionFull ver = {0}; _WlanRxFilterOperationCommandBuff_t RxFilterIdMask = {0}; unsigned char ucVal = 1; unsigned char ucConfigOpt = 0; unsigned char ucConfigLen = 0; unsigned char ucPower = 0; long lRetVal = -1; long lMode = -1; lMode = sl_Start(0, 0, 0); ASSERT_ON_ERROR(lMode); if (ROLE_STA != lMode) { if (ROLE_AP == lMode) { while(!IS_IP_ACQUIRED(g_ulStatus)) { #ifndef SL_PLATFORM_MULTI_THREADED _SlNonOsMainLoopTask(); #endif } } lRetVal = sl_WlanSetMode(ROLE_STA); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_Stop(0xFF); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_Start(0, 0, 0); ASSERT_ON_ERROR(lRetVal); if (ROLE_STA != lRetVal) { return DEVICE_NOT_IN_STATION_MODE; } } ucConfigOpt = SL_DEVICE_GENERAL_VERSION; ucConfigLen = sizeof(ver); lRetVal = sl_DevGet(SL_DEVICE_GENERAL_CONFIGURATION, &ucConfigOpt, &ucConfigLen, (unsigned char *)(&ver)); ASSERT_ON_ERROR(lRetVal); UART_PRINT("Host Driver Version: %s\n\r",SL_DRIVER_VERSION); UART_PRINT("Build Version %d.%d.%d.%d.31.%d.%d.%d.%d.%d.%d.%d.%d\n\r", ver.NwpVersion[0],ver.NwpVersion[1],ver.NwpVersion[2],ver.NwpVersion[3], ver.ChipFwAndPhyVersion.FwVersion[0],ver.ChipFwAndPhyVersion.FwVersion[1], ver.ChipFwAndPhyVersion.FwVersion[2],ver.ChipFwAndPhyVersion.FwVersion[3], ver.ChipFwAndPhyVersion.PhyVersion[0],ver.ChipFwAndPhyVersion.PhyVersion[1], ver.ChipFwAndPhyVersion.PhyVersion[2],ver.ChipFwAndPhyVersion.PhyVersion[3]); lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1, 0, 0, 0, 1), NULL, 0); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_WlanProfileDel(0xFF); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_WlanDisconnect(); if(0 == lRetVal) { while(IS_CONNECTED(g_ulStatus)) { #ifndef SL_PLATFORM_MULTI_THREADED _SlNonOsMainLoopTask(); #endif } } lRetVal = sl_NetCfgSet(SL_IPV4_STA_P2P_CL_DHCP_ENABLE,1,1,&ucVal); ASSERT_ON_ERROR(lRetVal); ucConfigOpt = SL_SCAN_POLICY(0); lRetVal = sl_WlanPolicySet(SL_POLICY_SCAN , ucConfigOpt, NULL, 0); ASSERT_ON_ERROR(lRetVal); ucPower = 0; lRetVal = sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, WLAN_GENERAL_PARAM_OPT_STA_TX_POWER, 1, (unsigned char *)&ucPower); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_WlanPolicySet(SL_POLICY_PM , SL_NORMAL_POLICY, NULL, 0); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_NetAppMDNSUnRegisterService(0, 0); ASSERT_ON_ERROR(lRetVal); memset(RxFilterIdMask.FilterIdMask, 0xFF, 8); lRetVal = sl_WlanRxFilterSet(SL_REMOVE_RX_FILTER, (_u8 *)&RxFilterIdMask, sizeof(_WlanRxFilterOperationCommandBuff_t)); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_Stop(SL_STOP_TIMEOUT); ASSERT_ON_ERROR(lRetVal); InitializeAppVariables(); return lRetVal; }
[ "static", "long", "ConfigureSimpleLinkToDefaultState", "(", ")", "{", "SlVersionFull", "ver", "=", "{", "0", "}", ";", "_WlanRxFilterOperationCommandBuff_t", "RxFilterIdMask", "=", "{", "0", "}", ";", "unsigned", "char", "ucVal", "=", "1", ";", "unsigned", "char", "ucConfigOpt", "=", "0", ";", "unsigned", "char", "ucConfigLen", "=", "0", ";", "unsigned", "char", "ucPower", "=", "0", ";", "long", "lRetVal", "=", "-1", ";", "long", "lMode", "=", "-1", ";", "lMode", "=", "sl_Start", "(", "0", ",", "0", ",", "0", ")", ";", "ASSERT_ON_ERROR", "(", "lMode", ")", ";", "if", "(", "ROLE_STA", "!=", "lMode", ")", "{", "if", "(", "ROLE_AP", "==", "lMode", ")", "{", "while", "(", "!", "IS_IP_ACQUIRED", "(", "g_ulStatus", ")", ")", "{", "#ifndef", "SL_PLATFORM_MULTI_THREADED", "_SlNonOsMainLoopTask", "(", ")", ";", "#endif", "}", "}", "lRetVal", "=", "sl_WlanSetMode", "(", "ROLE_STA", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "lRetVal", "=", "sl_Stop", "(", "0xFF", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "lRetVal", "=", "sl_Start", "(", "0", ",", "0", ",", "0", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "if", "(", "ROLE_STA", "!=", "lRetVal", ")", "{", "return", "DEVICE_NOT_IN_STATION_MODE", ";", "}", "}", "ucConfigOpt", "=", "SL_DEVICE_GENERAL_VERSION", ";", "ucConfigLen", "=", "sizeof", "(", "ver", ")", ";", "lRetVal", "=", "sl_DevGet", "(", "SL_DEVICE_GENERAL_CONFIGURATION", ",", "&", "ucConfigOpt", ",", "&", "ucConfigLen", ",", "(", "unsigned", "char", "*", ")", "(", "&", "ver", ")", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "UART_PRINT", "(", "\"", "\\n", "\\r", "\"", ",", "SL_DRIVER_VERSION", ")", ";", "UART_PRINT", "(", "\"", "\\n", "\\r", "\"", ",", "ver", ".", "NwpVersion", "[", "0", "]", ",", "ver", ".", "NwpVersion", "[", "1", "]", ",", "ver", ".", "NwpVersion", "[", "2", "]", ",", "ver", ".", "NwpVersion", "[", "3", "]", ",", "ver", ".", "ChipFwAndPhyVersion", ".", "FwVersion", "[", "0", "]", ",", "ver", ".", "ChipFwAndPhyVersion", ".", "FwVersion", "[", "1", "]", ",", "ver", ".", "ChipFwAndPhyVersion", ".", "FwVersion", "[", "2", "]", ",", "ver", ".", "ChipFwAndPhyVersion", ".", "FwVersion", "[", "3", "]", ",", "ver", ".", "ChipFwAndPhyVersion", ".", "PhyVersion", "[", "0", "]", ",", "ver", ".", "ChipFwAndPhyVersion", ".", "PhyVersion", "[", "1", "]", ",", "ver", ".", "ChipFwAndPhyVersion", ".", "PhyVersion", "[", "2", "]", ",", "ver", ".", "ChipFwAndPhyVersion", ".", "PhyVersion", "[", "3", "]", ")", ";", "lRetVal", "=", "sl_WlanPolicySet", "(", "SL_POLICY_CONNECTION", ",", "SL_CONNECTION_POLICY", "(", "1", ",", "0", ",", "0", ",", "0", ",", "1", ")", ",", "NULL", ",", "0", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "lRetVal", "=", "sl_WlanProfileDel", "(", "0xFF", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "lRetVal", "=", "sl_WlanDisconnect", "(", ")", ";", "if", "(", "0", "==", "lRetVal", ")", "{", "while", "(", "IS_CONNECTED", "(", "g_ulStatus", ")", ")", "{", "#ifndef", "SL_PLATFORM_MULTI_THREADED", "_SlNonOsMainLoopTask", "(", ")", ";", "#endif", "}", "}", "lRetVal", "=", "sl_NetCfgSet", "(", "SL_IPV4_STA_P2P_CL_DHCP_ENABLE", ",", "1", ",", "1", ",", "&", "ucVal", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "ucConfigOpt", "=", "SL_SCAN_POLICY", "(", "0", ")", ";", "lRetVal", "=", "sl_WlanPolicySet", "(", "SL_POLICY_SCAN", ",", "ucConfigOpt", ",", "NULL", ",", "0", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "ucPower", "=", "0", ";", "lRetVal", "=", "sl_WlanSet", "(", "SL_WLAN_CFG_GENERAL_PARAM_ID", ",", "WLAN_GENERAL_PARAM_OPT_STA_TX_POWER", ",", "1", ",", "(", "unsigned", "char", "*", ")", "&", "ucPower", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "lRetVal", "=", "sl_WlanPolicySet", "(", "SL_POLICY_PM", ",", "SL_NORMAL_POLICY", ",", "NULL", ",", "0", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "lRetVal", "=", "sl_NetAppMDNSUnRegisterService", "(", "0", ",", "0", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "memset", "(", "RxFilterIdMask", ".", "FilterIdMask", ",", "0xFF", ",", "8", ")", ";", "lRetVal", "=", "sl_WlanRxFilterSet", "(", "SL_REMOVE_RX_FILTER", ",", "(", "_u8", "*", ")", "&", "RxFilterIdMask", ",", "sizeof", "(", "_WlanRxFilterOperationCommandBuff_t", ")", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "lRetVal", "=", "sl_Stop", "(", "SL_STOP_TIMEOUT", ")", ";", "ASSERT_ON_ERROR", "(", "lRetVal", ")", ";", "InitializeAppVariables", "(", ")", ";", "return", "lRetVal", ";", "}" ]
\brief This function puts the device in its default state.
[ "\\", "brief", "This", "function", "puts", "the", "device", "in", "its", "default", "state", "." ]
[ "// If the device is not in station-mode, try configuring it in station-mode \r", "// If the device is in AP mode, we need to wait for this event \r", "// before doing anything \r", "// Switch to STA role and restart \r", "// Check if the device is in station again \r", "// We don't want to proceed if the device is not coming up in STA-mode \r", "// Get the device's version-information\r", "// Set connection policy to Auto + SmartConfig \r", "// (Device's default connection policy)\r", "// Remove all profiles\r", "//\r", "// Device in station-mode. Disconnect previous connection if any\r", "// The function returns 0 if 'Disconnected done', negative number if already\r", "// disconnected Wait for 'disconnection' event if 0 is returned, Ignore \r", "// other return-codes\r", "//\r", "// Wait\r", "// Enable DHCP client\r", "// Disable scan\r", "// Set Tx power level for station mode\r", "// Number between 0-15, as dB offset from max power - 0 will set max power\r", "// Set PM policy to normal\r", "// Unregister mDNS services\r", "// Remove all 64 filters (8*8)\r", "// Success\r" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
485ffb2c4fe3fb44322d9dd98058e32e7b0e5d45
csylo/launchpad-tcp
lp1-tcp-send-file/main.c
[ "BSD-3-Clause" ]
C
BsdTcpClient
int
int BsdTcpClient(unsigned short usPort) { int iCounter; short sTestBufLen; SlSockAddrIn_t sAddr; int iAddrSize; int iSockID; int iStatus; long lLoopCount = 0; //File IO from: //http://www.multisilicon.com/_a/blog/a25365269~/group___file_system.html#ga6a9aaae1813255fa13c7d6bc26c2904c //Requires #include <fs.h> char* myFileName = "data_to_send.txt"; unsigned long MaxSize = 63 * 1024; //62.5K is max file size long myFileHandle = -1; long ClientRetVal; //negative retval is an error unsigned long Offset = 0; //open the file ClientRetVal = sl_FsOpen((unsigned char *) myFileName, FS_MODE_OPEN_READ, NULL, &myFileHandle); Offset = 0; //read 1024 (or remaining) bytes from the file ClientRetVal = sl_FsRead( myFileHandle, Offset, (unsigned char *) g_cBsdBuf, 1024); //last param is an int, length of received data //add null terminator to what was read g_cBsdBuf[15] = '\0'; sTestBufLen = BUF_SIZE; //filling the TCP server socket address sAddr.sin_family = SL_AF_INET; sAddr.sin_port = sl_Htons((unsigned short)usPort); sAddr.sin_addr.s_addr = sl_Htonl((unsigned int)g_ulDestinationIp); iAddrSize = sizeof(SlSockAddrIn_t); //creating a TCP socket iSockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0); if( iSockID < 0 ){ ASSERT_ON_ERROR(SOCKET_CREATE_ERROR); } //connecting to TCP server iStatus = sl_Connect(iSockID, ( SlSockAddr_t *)&sAddr, iAddrSize); if( iStatus < 0 ){ // error sl_Close(iSockID); ASSERT_ON_ERROR(CONNECT_ERROR); } //sending multiple packets to the TCP server (1 packet = 1024 bytes) while (lLoopCount < g_ulPacketCount){ //sending packet iStatus = sl_Send(iSockID, g_cBsdBuf, ClientRetVal, 0); if(iStatus < 0){ //error sl_Close(iSockID); ASSERT_ON_ERROR(SEND_ERROR); } lLoopCount++; } Report("Finished sending packets.\n\r"); iStatus = sl_Close(iSockID); //closing the socket after sending bytes ASSERT_ON_ERROR(iStatus); //close file ClientRetVal = sl_FsClose(myFileHandle, NULL, NULL , 0); //return 0 means success return ClientRetVal; }
//**************************************************************************** // //! \brief Opening a TCP client side socket and sending data //! //! This function conneccts to the listening server and sends the file //! in parts // //****************************************************************************
\brief Opening a TCP client side socket and sending data This function conneccts to the listening server and sends the file in parts
[ "\\", "brief", "Opening", "a", "TCP", "client", "side", "socket", "and", "sending", "data", "This", "function", "conneccts", "to", "the", "listening", "server", "and", "sends", "the", "file", "in", "parts" ]
int BsdTcpClient(unsigned short usPort) { int iCounter; short sTestBufLen; SlSockAddrIn_t sAddr; int iAddrSize; int iSockID; int iStatus; long lLoopCount = 0; char* myFileName = "data_to_send.txt"; unsigned long MaxSize = 63 * 1024; long myFileHandle = -1; long ClientRetVal; unsigned long Offset = 0; ClientRetVal = sl_FsOpen((unsigned char *) myFileName, FS_MODE_OPEN_READ, NULL, &myFileHandle); Offset = 0; ClientRetVal = sl_FsRead( myFileHandle, Offset, (unsigned char *) g_cBsdBuf, 1024); g_cBsdBuf[15] = '\0'; sTestBufLen = BUF_SIZE; sAddr.sin_family = SL_AF_INET; sAddr.sin_port = sl_Htons((unsigned short)usPort); sAddr.sin_addr.s_addr = sl_Htonl((unsigned int)g_ulDestinationIp); iAddrSize = sizeof(SlSockAddrIn_t); iSockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0); if( iSockID < 0 ){ ASSERT_ON_ERROR(SOCKET_CREATE_ERROR); } iStatus = sl_Connect(iSockID, ( SlSockAddr_t *)&sAddr, iAddrSize); if( iStatus < 0 ){ sl_Close(iSockID); ASSERT_ON_ERROR(CONNECT_ERROR); } while (lLoopCount < g_ulPacketCount){ iStatus = sl_Send(iSockID, g_cBsdBuf, ClientRetVal, 0); if(iStatus < 0){ sl_Close(iSockID); ASSERT_ON_ERROR(SEND_ERROR); } lLoopCount++; } Report("Finished sending packets.\n\r"); iStatus = sl_Close(iSockID); ASSERT_ON_ERROR(iStatus); ClientRetVal = sl_FsClose(myFileHandle, NULL, NULL , 0); return ClientRetVal; }
[ "int", "BsdTcpClient", "(", "unsigned", "short", "usPort", ")", "{", "int", "iCounter", ";", "short", "sTestBufLen", ";", "SlSockAddrIn_t", "sAddr", ";", "int", "iAddrSize", ";", "int", "iSockID", ";", "int", "iStatus", ";", "long", "lLoopCount", "=", "0", ";", "char", "*", "myFileName", "=", "\"", "\"", ";", "unsigned", "long", "MaxSize", "=", "63", "*", "1024", ";", "long", "myFileHandle", "=", "-1", ";", "long", "ClientRetVal", ";", "unsigned", "long", "Offset", "=", "0", ";", "ClientRetVal", "=", "sl_FsOpen", "(", "(", "unsigned", "char", "*", ")", "myFileName", ",", "FS_MODE_OPEN_READ", ",", "NULL", ",", "&", "myFileHandle", ")", ";", "Offset", "=", "0", ";", "ClientRetVal", "=", "sl_FsRead", "(", "myFileHandle", ",", "Offset", ",", "(", "unsigned", "char", "*", ")", "g_cBsdBuf", ",", "1024", ")", ";", "g_cBsdBuf", "[", "15", "]", "=", "'", "\\0", "'", ";", "sTestBufLen", "=", "BUF_SIZE", ";", "sAddr", ".", "sin_family", "=", "SL_AF_INET", ";", "sAddr", ".", "sin_port", "=", "sl_Htons", "(", "(", "unsigned", "short", ")", "usPort", ")", ";", "sAddr", ".", "sin_addr", ".", "s_addr", "=", "sl_Htonl", "(", "(", "unsigned", "int", ")", "g_ulDestinationIp", ")", ";", "iAddrSize", "=", "sizeof", "(", "SlSockAddrIn_t", ")", ";", "iSockID", "=", "sl_Socket", "(", "SL_AF_INET", ",", "SL_SOCK_STREAM", ",", "0", ")", ";", "if", "(", "iSockID", "<", "0", ")", "{", "ASSERT_ON_ERROR", "(", "SOCKET_CREATE_ERROR", ")", ";", "}", "iStatus", "=", "sl_Connect", "(", "iSockID", ",", "(", "SlSockAddr_t", "*", ")", "&", "sAddr", ",", "iAddrSize", ")", ";", "if", "(", "iStatus", "<", "0", ")", "{", "sl_Close", "(", "iSockID", ")", ";", "ASSERT_ON_ERROR", "(", "CONNECT_ERROR", ")", ";", "}", "while", "(", "lLoopCount", "<", "g_ulPacketCount", ")", "{", "iStatus", "=", "sl_Send", "(", "iSockID", ",", "g_cBsdBuf", ",", "ClientRetVal", ",", "0", ")", ";", "if", "(", "iStatus", "<", "0", ")", "{", "sl_Close", "(", "iSockID", ")", ";", "ASSERT_ON_ERROR", "(", "SEND_ERROR", ")", ";", "}", "lLoopCount", "++", ";", "}", "Report", "(", "\"", "\\n", "\\r", "\"", ")", ";", "iStatus", "=", "sl_Close", "(", "iSockID", ")", ";", "ASSERT_ON_ERROR", "(", "iStatus", ")", ";", "ClientRetVal", "=", "sl_FsClose", "(", "myFileHandle", ",", "NULL", ",", "NULL", ",", "0", ")", ";", "return", "ClientRetVal", ";", "}" ]
\brief Opening a TCP client side socket and sending data This function conneccts to the listening server and sends the file in parts
[ "\\", "brief", "Opening", "a", "TCP", "client", "side", "socket", "and", "sending", "data", "This", "function", "conneccts", "to", "the", "listening", "server", "and", "sends", "the", "file", "in", "parts" ]
[ "//File IO from:\r", "//http://www.multisilicon.com/_a/blog/a25365269~/group___file_system.html#ga6a9aaae1813255fa13c7d6bc26c2904c\r", "//Requires #include <fs.h>\r", "//62.5K is max file size\r", "//negative retval is an error\r", "//open the file\r", "//read 1024 (or remaining) bytes from the file\r", "//last param is an int, length of received data\r", "//add null terminator to what was read\r", "//filling the TCP server socket address\r", "//creating a TCP socket\r", "//connecting to TCP server\r", "// error\r", "//sending multiple packets to the TCP server (1 packet = 1024 bytes)\r", "//sending packet\r", "//error\r", "//closing the socket after sending bytes\r", "//close file\r", "//return 0 means success\r" ]
[ { "param": "usPort", "type": "unsigned short" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "usPort", "type": "unsigned short", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
0d0a58ab744487371af9ea9fbdda10c34a2988f4
Hackerdd/DAPProg
src/DAP_config.h
[ "MIT" ]
C
PORT_SWD_SETUP
void
static void PORT_SWD_SETUP(void) { GPIO_InitTypeDef GPIO_InitStruct; SWD_GPIO->BSRR = PIN_SWCLK | PIN_SWDIO; GPIO_InitStruct.GPIO_Pin = PIN_SWCLK | PIN_SWDIO; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(SWD_GPIO, &GPIO_InitStruct); }
/** Setup SWD I/O pins: SWCLK, SWDIO, and nRESET. - SWCLK, SWDIO, nRESET to output mode and set to default high level. */
Setup SWD I/O pins: SWCLK, SWDIO, and nRESET. SWCLK, SWDIO, nRESET to output mode and set to default high level.
[ "Setup", "SWD", "I", "/", "O", "pins", ":", "SWCLK", "SWDIO", "and", "nRESET", ".", "SWCLK", "SWDIO", "nRESET", "to", "output", "mode", "and", "set", "to", "default", "high", "level", "." ]
static void PORT_SWD_SETUP(void) { GPIO_InitTypeDef GPIO_InitStruct; SWD_GPIO->BSRR = PIN_SWCLK | PIN_SWDIO; GPIO_InitStruct.GPIO_Pin = PIN_SWCLK | PIN_SWDIO; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(SWD_GPIO, &GPIO_InitStruct); }
[ "static", "void", "PORT_SWD_SETUP", "(", "void", ")", "{", "GPIO_InitTypeDef", "GPIO_InitStruct", ";", "SWD_GPIO", "->", "BSRR", "=", "PIN_SWCLK", "|", "PIN_SWDIO", ";", "GPIO_InitStruct", ".", "GPIO_Pin", "=", "PIN_SWCLK", "|", "PIN_SWDIO", ";", "GPIO_InitStruct", ".", "GPIO_Mode", "=", "GPIO_Mode_Out_PP", ";", "GPIO_InitStruct", ".", "GPIO_Speed", "=", "GPIO_Speed_50MHz", ";", "GPIO_Init", "(", "SWD_GPIO", ",", "&", "GPIO_InitStruct", ")", ";", "}" ]
Setup SWD I/O pins: SWCLK, SWDIO, and nRESET.
[ "Setup", "SWD", "I", "/", "O", "pins", ":", "SWCLK", "SWDIO", "and", "nRESET", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
3141c9df36dda9e484746d33ff3c0628f7471c35
kalyanam-FMTGA/ray-original
src/util/dctimestep.c
[ "BSD-3-Clause-LBNL" ]
C
cm_load
CMATRIX
static CMATRIX * cm_load(const char *fname, int nrows, int ncols, int dtype) { FILE *fp = stdin; CMATRIX *cm; if (ncols <= 0) error(USER, "Non-positive number of columns"); if (fname == NULL) fname = "<stdin>"; else if ((fp = fopen(fname, "r")) == NULL) { sprintf(errmsg, "cannot open file '%s'", fname); error(SYSTEM, errmsg); } #ifdef getc_unlocked flockfile(fp); #endif if (dtype != DTascii) SET_FILE_BINARY(fp); /* doesn't really work */ if (dtype == DTfromHeader) dtype = getDTfromHeader(fp); switch (dtype) { case DTascii: case DTfloat: case DTdouble: break; default: error(USER, "unexpected data type in cm_load()"); } if (nrows <= 0) { /* don't know length? */ int guessrows = 147; /* usually big enough */ if ((dtype != DTascii) & (fp != stdin)) { long startpos = ftell(fp); if (fseek(fp, 0L, SEEK_END) == 0) { long endpos = ftell(fp); long elemsiz = 3*(dtype==DTfloat ? sizeof(float) : sizeof(double)); if ((endpos - startpos) % (ncols*elemsiz)) { sprintf(errmsg, "improper length for binary file '%s'", fname); error(USER, errmsg); } guessrows = (endpos - startpos)/(ncols*elemsiz); if (fseek(fp, startpos, SEEK_SET) < 0) { sprintf(errmsg, "fseek() error on file '%s'", fname); error(SYSTEM, errmsg); } nrows = guessrows; /* we're confident */ } } cm = cm_alloc(guessrows, ncols); } else cm = cm_alloc(nrows, ncols); if (cm == NULL) /* XXX never happens */ return(NULL); if (dtype == DTascii) { /* read text file */ int maxrow = (nrows > 0 ? nrows : 32000); int r, c; for (r = 0; r < maxrow; r++) { if (r >= cm->nrows) /* need more space? */ cm = cm_resize(cm, 2*cm->nrows); for (c = 0; c < ncols; c++) { COLORV *cv = cm_lval(cm,r,c); if (fscanf(fp, COLSPEC, cv, cv+1, cv+2) != 3) if ((nrows <= 0) & (r > 0) & !c) { cm = cm_resize(cm, maxrow=r); break; } else goto EOFerror; } } while ((c = getc(fp)) != EOF) if (!isspace(c)) { sprintf(errmsg, "unexpected data at end of ascii file %s", fname); error(WARNING, errmsg); break; } } else { /* read binary file */ if (sizeof(COLORV) == (dtype==DTfloat ? sizeof(float) : sizeof(double))) { int nread = 0; do { /* read all we can */ nread += fread(cm->cmem + 3*nread, 3*sizeof(COLORV), cm->nrows*cm->ncols - nread, fp); if (nrows <= 0) { /* unknown length */ if (nread == cm->nrows*cm->ncols) /* need more space? */ cm = cm_resize(cm, 2*cm->nrows); else if (nread && !(nread % cm->ncols)) /* seem to be done */ cm = cm_resize(cm, nread/cm->ncols); else /* ended mid-row */ goto EOFerror; } else if (nread < cm->nrows*cm->ncols) goto EOFerror; } while (nread < cm->nrows*cm->ncols); } else if (dtype == DTdouble) { double dc[3]; /* load from double */ COLORV *cvp = cm->cmem; int n = nrows*ncols; if (n <= 0) goto not_handled; while (n--) { if (fread(dc, sizeof(double), 3, fp) != 3) goto EOFerror; copycolor(cvp, dc); cvp += 3; } } else /* dtype == DTfloat */ { float fc[3]; /* load from float */ COLORV *cvp = cm->cmem; int n = nrows*ncols; if (n <= 0) goto not_handled; while (n--) { if (fread(fc, sizeof(float), 3, fp) != 3) goto EOFerror; copycolor(cvp, fc); cvp += 3; } } if (fgetc(fp) != EOF) { sprintf(errmsg, "unexpected data at end of binary file %s", fname); error(WARNING, errmsg); } } if (fp != stdin) fclose(fp); #ifdef getc_unlocked else funlockfile(fp); #endif return(cm); EOFerror: sprintf(errmsg, "unexpected EOF reading %s", fname); error(USER, errmsg); not_handled: error(INTERNAL, "unhandled data size or length in cm_load()"); return(NULL); /* gratis return */ }
/* Allocate and load a matrix from the given file (or stdin if NULL) */
Allocate and load a matrix from the given file (or stdin if NULL)
[ "Allocate", "and", "load", "a", "matrix", "from", "the", "given", "file", "(", "or", "stdin", "if", "NULL", ")" ]
static CMATRIX * cm_load(const char *fname, int nrows, int ncols, int dtype) { FILE *fp = stdin; CMATRIX *cm; if (ncols <= 0) error(USER, "Non-positive number of columns"); if (fname == NULL) fname = "<stdin>"; else if ((fp = fopen(fname, "r")) == NULL) { sprintf(errmsg, "cannot open file '%s'", fname); error(SYSTEM, errmsg); } #ifdef getc_unlocked flockfile(fp); #endif if (dtype != DTascii) SET_FILE_BINARY(fp); if (dtype == DTfromHeader) dtype = getDTfromHeader(fp); switch (dtype) { case DTascii: case DTfloat: case DTdouble: break; default: error(USER, "unexpected data type in cm_load()"); } if (nrows <= 0) { int guessrows = 147; if ((dtype != DTascii) & (fp != stdin)) { long startpos = ftell(fp); if (fseek(fp, 0L, SEEK_END) == 0) { long endpos = ftell(fp); long elemsiz = 3*(dtype==DTfloat ? sizeof(float) : sizeof(double)); if ((endpos - startpos) % (ncols*elemsiz)) { sprintf(errmsg, "improper length for binary file '%s'", fname); error(USER, errmsg); } guessrows = (endpos - startpos)/(ncols*elemsiz); if (fseek(fp, startpos, SEEK_SET) < 0) { sprintf(errmsg, "fseek() error on file '%s'", fname); error(SYSTEM, errmsg); } nrows = guessrows; } } cm = cm_alloc(guessrows, ncols); } else cm = cm_alloc(nrows, ncols); if (cm == NULL) return(NULL); if (dtype == DTascii) { int maxrow = (nrows > 0 ? nrows : 32000); int r, c; for (r = 0; r < maxrow; r++) { if (r >= cm->nrows) cm = cm_resize(cm, 2*cm->nrows); for (c = 0; c < ncols; c++) { COLORV *cv = cm_lval(cm,r,c); if (fscanf(fp, COLSPEC, cv, cv+1, cv+2) != 3) if ((nrows <= 0) & (r > 0) & !c) { cm = cm_resize(cm, maxrow=r); break; } else goto EOFerror; } } while ((c = getc(fp)) != EOF) if (!isspace(c)) { sprintf(errmsg, "unexpected data at end of ascii file %s", fname); error(WARNING, errmsg); break; } } else { if (sizeof(COLORV) == (dtype==DTfloat ? sizeof(float) : sizeof(double))) { int nread = 0; do { nread += fread(cm->cmem + 3*nread, 3*sizeof(COLORV), cm->nrows*cm->ncols - nread, fp); if (nrows <= 0) { if (nread == cm->nrows*cm->ncols) cm = cm_resize(cm, 2*cm->nrows); else if (nread && !(nread % cm->ncols)) cm = cm_resize(cm, nread/cm->ncols); else goto EOFerror; } else if (nread < cm->nrows*cm->ncols) goto EOFerror; } while (nread < cm->nrows*cm->ncols); } else if (dtype == DTdouble) { double dc[3]; COLORV *cvp = cm->cmem; int n = nrows*ncols; if (n <= 0) goto not_handled; while (n--) { if (fread(dc, sizeof(double), 3, fp) != 3) goto EOFerror; copycolor(cvp, dc); cvp += 3; } } else { float fc[3]; COLORV *cvp = cm->cmem; int n = nrows*ncols; if (n <= 0) goto not_handled; while (n--) { if (fread(fc, sizeof(float), 3, fp) != 3) goto EOFerror; copycolor(cvp, fc); cvp += 3; } } if (fgetc(fp) != EOF) { sprintf(errmsg, "unexpected data at end of binary file %s", fname); error(WARNING, errmsg); } } if (fp != stdin) fclose(fp); #ifdef getc_unlocked else funlockfile(fp); #endif return(cm); EOFerror: sprintf(errmsg, "unexpected EOF reading %s", fname); error(USER, errmsg); not_handled: error(INTERNAL, "unhandled data size or length in cm_load()"); return(NULL); }
[ "static", "CMATRIX", "*", "cm_load", "(", "const", "char", "*", "fname", ",", "int", "nrows", ",", "int", "ncols", ",", "int", "dtype", ")", "{", "FILE", "*", "fp", "=", "stdin", ";", "CMATRIX", "*", "cm", ";", "if", "(", "ncols", "<=", "0", ")", "error", "(", "USER", ",", "\"", "\"", ")", ";", "if", "(", "fname", "==", "NULL", ")", "fname", "=", "\"", "\"", ";", "else", "if", "(", "(", "fp", "=", "fopen", "(", "fname", ",", "\"", "\"", ")", ")", "==", "NULL", ")", "{", "sprintf", "(", "errmsg", ",", "\"", "\"", ",", "fname", ")", ";", "error", "(", "SYSTEM", ",", "errmsg", ")", ";", "}", "#ifdef", "getc_unlocked", "flockfile", "(", "fp", ")", ";", "#endif", "if", "(", "dtype", "!=", "DTascii", ")", "SET_FILE_BINARY", "(", "fp", ")", ";", "if", "(", "dtype", "==", "DTfromHeader", ")", "dtype", "=", "getDTfromHeader", "(", "fp", ")", ";", "switch", "(", "dtype", ")", "{", "case", "DTascii", ":", "case", "DTfloat", ":", "case", "DTdouble", ":", "break", ";", "default", ":", "error", "(", "USER", ",", "\"", "\"", ")", ";", "}", "if", "(", "nrows", "<=", "0", ")", "{", "int", "guessrows", "=", "147", ";", "if", "(", "(", "dtype", "!=", "DTascii", ")", "&", "(", "fp", "!=", "stdin", ")", ")", "{", "long", "startpos", "=", "ftell", "(", "fp", ")", ";", "if", "(", "fseek", "(", "fp", ",", "0L", ",", "SEEK_END", ")", "==", "0", ")", "{", "long", "endpos", "=", "ftell", "(", "fp", ")", ";", "long", "elemsiz", "=", "3", "*", "(", "dtype", "==", "DTfloat", "?", "sizeof", "(", "float", ")", ":", "sizeof", "(", "double", ")", ")", ";", "if", "(", "(", "endpos", "-", "startpos", ")", "%", "(", "ncols", "*", "elemsiz", ")", ")", "{", "sprintf", "(", "errmsg", ",", "\"", "\"", ",", "fname", ")", ";", "error", "(", "USER", ",", "errmsg", ")", ";", "}", "guessrows", "=", "(", "endpos", "-", "startpos", ")", "/", "(", "ncols", "*", "elemsiz", ")", ";", "if", "(", "fseek", "(", "fp", ",", "startpos", ",", "SEEK_SET", ")", "<", "0", ")", "{", "sprintf", "(", "errmsg", ",", "\"", "\"", ",", "fname", ")", ";", "error", "(", "SYSTEM", ",", "errmsg", ")", ";", "}", "nrows", "=", "guessrows", ";", "}", "}", "cm", "=", "cm_alloc", "(", "guessrows", ",", "ncols", ")", ";", "}", "else", "cm", "=", "cm_alloc", "(", "nrows", ",", "ncols", ")", ";", "if", "(", "cm", "==", "NULL", ")", "return", "(", "NULL", ")", ";", "if", "(", "dtype", "==", "DTascii", ")", "{", "int", "maxrow", "=", "(", "nrows", ">", "0", "?", "nrows", ":", "32000", ")", ";", "int", "r", ",", "c", ";", "for", "(", "r", "=", "0", ";", "r", "<", "maxrow", ";", "r", "++", ")", "{", "if", "(", "r", ">=", "cm", "->", "nrows", ")", "cm", "=", "cm_resize", "(", "cm", ",", "2", "*", "cm", "->", "nrows", ")", ";", "for", "(", "c", "=", "0", ";", "c", "<", "ncols", ";", "c", "++", ")", "{", "COLORV", "*", "cv", "=", "cm_lval", "(", "cm", ",", "r", ",", "c", ")", ";", "if", "(", "fscanf", "(", "fp", ",", "COLSPEC", ",", "cv", ",", "cv", "+", "1", ",", "cv", "+", "2", ")", "!=", "3", ")", "if", "(", "(", "nrows", "<=", "0", ")", "&", "(", "r", ">", "0", ")", "&", "!", "c", ")", "{", "cm", "=", "cm_resize", "(", "cm", ",", "maxrow", "=", "r", ")", ";", "break", ";", "}", "else", "goto", "EOFerror", ";", "}", "}", "while", "(", "(", "c", "=", "getc", "(", "fp", ")", ")", "!=", "EOF", ")", "if", "(", "!", "isspace", "(", "c", ")", ")", "{", "sprintf", "(", "errmsg", ",", "\"", "\"", ",", "fname", ")", ";", "error", "(", "WARNING", ",", "errmsg", ")", ";", "break", ";", "}", "}", "else", "{", "if", "(", "sizeof", "(", "COLORV", ")", "==", "(", "dtype", "==", "DTfloat", "?", "sizeof", "(", "float", ")", ":", "sizeof", "(", "double", ")", ")", ")", "{", "int", "nread", "=", "0", ";", "do", "{", "nread", "+=", "fread", "(", "cm", "->", "cmem", "+", "3", "*", "nread", ",", "3", "*", "sizeof", "(", "COLORV", ")", ",", "cm", "->", "nrows", "*", "cm", "->", "ncols", "-", "nread", ",", "fp", ")", ";", "if", "(", "nrows", "<=", "0", ")", "{", "if", "(", "nread", "==", "cm", "->", "nrows", "*", "cm", "->", "ncols", ")", "cm", "=", "cm_resize", "(", "cm", ",", "2", "*", "cm", "->", "nrows", ")", ";", "else", "if", "(", "nread", "&&", "!", "(", "nread", "%", "cm", "->", "ncols", ")", ")", "cm", "=", "cm_resize", "(", "cm", ",", "nread", "/", "cm", "->", "ncols", ")", ";", "else", "goto", "EOFerror", ";", "}", "else", "if", "(", "nread", "<", "cm", "->", "nrows", "*", "cm", "->", "ncols", ")", "goto", "EOFerror", ";", "}", "while", "(", "nread", "<", "cm", "->", "nrows", "*", "cm", "->", "ncols", ")", ";", "}", "else", "if", "(", "dtype", "==", "DTdouble", ")", "{", "double", "dc", "[", "3", "]", ";", "COLORV", "*", "cvp", "=", "cm", "->", "cmem", ";", "int", "n", "=", "nrows", "*", "ncols", ";", "if", "(", "n", "<=", "0", ")", "goto", "not_handled", ";", "while", "(", "n", "--", ")", "{", "if", "(", "fread", "(", "dc", ",", "sizeof", "(", "double", ")", ",", "3", ",", "fp", ")", "!=", "3", ")", "goto", "EOFerror", ";", "copycolor", "(", "cvp", ",", "dc", ")", ";", "cvp", "+=", "3", ";", "}", "}", "else", "{", "float", "fc", "[", "3", "]", ";", "COLORV", "*", "cvp", "=", "cm", "->", "cmem", ";", "int", "n", "=", "nrows", "*", "ncols", ";", "if", "(", "n", "<=", "0", ")", "goto", "not_handled", ";", "while", "(", "n", "--", ")", "{", "if", "(", "fread", "(", "fc", ",", "sizeof", "(", "float", ")", ",", "3", ",", "fp", ")", "!=", "3", ")", "goto", "EOFerror", ";", "copycolor", "(", "cvp", ",", "fc", ")", ";", "cvp", "+=", "3", ";", "}", "}", "if", "(", "fgetc", "(", "fp", ")", "!=", "EOF", ")", "{", "sprintf", "(", "errmsg", ",", "\"", "\"", ",", "fname", ")", ";", "error", "(", "WARNING", ",", "errmsg", ")", ";", "}", "}", "if", "(", "fp", "!=", "stdin", ")", "fclose", "(", "fp", ")", ";", "#ifdef", "getc_unlocked", "else", "funlockfile", "(", "fp", ")", ";", "#endif", "return", "(", "cm", ")", ";", "EOFerror", ":", "sprintf", "(", "errmsg", ",", "\"", "\"", ",", "fname", ")", ";", "error", "(", "USER", ",", "errmsg", ")", ";", "not_handled", ":", "error", "(", "INTERNAL", ",", "\"", "\"", ")", ";", "return", "(", "NULL", ")", ";", "}" ]
Allocate and load a matrix from the given file (or stdin if NULL)
[ "Allocate", "and", "load", "a", "matrix", "from", "the", "given", "file", "(", "or", "stdin", "if", "NULL", ")" ]
[ "/* doesn't really work */", "/* don't know length? */", "/* usually big enough */", "/* we're confident */", "/* XXX never happens */", "/* read text file */", "/* need more space? */", "/* read binary file */", "/* read all we can */", "/* unknown length */", "/* need more space? */", "/* seem to be done */", "/* ended mid-row */", "/* load from double */", "/* dtype == DTfloat */", "/* load from float */", "/* gratis return */" ]
[ { "param": "fname", "type": "char" }, { "param": "nrows", "type": "int" }, { "param": "ncols", "type": "int" }, { "param": "dtype", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fname", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "nrows", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "ncols", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "dtype", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3141c9df36dda9e484746d33ff3c0628f7471c35
kalyanam-FMTGA/ray-original
src/util/dctimestep.c
[ "BSD-3-Clause-LBNL" ]
C
cm_column
CMATRIX
static CMATRIX * cm_column(const CMATRIX *cm, int c) { CMATRIX *cvr; int dr; if ((c < 0) | (c >= cm->ncols)) error(INTERNAL, "column requested outside matrix"); cvr = cm_alloc(cm->nrows, 1); if (cvr == NULL) return(NULL); for (dr = 0; dr < cm->nrows; dr++) { const COLORV *sp = cm_lval(cm,dr,c); COLORV *dp = cv_lval(cvr,dr); dp[0] = sp[0]; dp[1] = sp[1]; dp[2] = sp[2]; } return(cvr); }
/* Extract a column vector from a matrix */
Extract a column vector from a matrix
[ "Extract", "a", "column", "vector", "from", "a", "matrix" ]
static CMATRIX * cm_column(const CMATRIX *cm, int c) { CMATRIX *cvr; int dr; if ((c < 0) | (c >= cm->ncols)) error(INTERNAL, "column requested outside matrix"); cvr = cm_alloc(cm->nrows, 1); if (cvr == NULL) return(NULL); for (dr = 0; dr < cm->nrows; dr++) { const COLORV *sp = cm_lval(cm,dr,c); COLORV *dp = cv_lval(cvr,dr); dp[0] = sp[0]; dp[1] = sp[1]; dp[2] = sp[2]; } return(cvr); }
[ "static", "CMATRIX", "*", "cm_column", "(", "const", "CMATRIX", "*", "cm", ",", "int", "c", ")", "{", "CMATRIX", "*", "cvr", ";", "int", "dr", ";", "if", "(", "(", "c", "<", "0", ")", "|", "(", "c", ">=", "cm", "->", "ncols", ")", ")", "error", "(", "INTERNAL", ",", "\"", "\"", ")", ";", "cvr", "=", "cm_alloc", "(", "cm", "->", "nrows", ",", "1", ")", ";", "if", "(", "cvr", "==", "NULL", ")", "return", "(", "NULL", ")", ";", "for", "(", "dr", "=", "0", ";", "dr", "<", "cm", "->", "nrows", ";", "dr", "++", ")", "{", "const", "COLORV", "*", "sp", "=", "cm_lval", "(", "cm", ",", "dr", ",", "c", ")", ";", "COLORV", "*", "dp", "=", "cv_lval", "(", "cvr", ",", "dr", ")", ";", "dp", "[", "0", "]", "=", "sp", "[", "0", "]", ";", "dp", "[", "1", "]", "=", "sp", "[", "1", "]", ";", "dp", "[", "2", "]", "=", "sp", "[", "2", "]", ";", "}", "return", "(", "cvr", ")", ";", "}" ]
Extract a column vector from a matrix
[ "Extract", "a", "column", "vector", "from", "a", "matrix" ]
[]
[ { "param": "cm", "type": "CMATRIX" }, { "param": "c", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "cm", "type": "CMATRIX", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "c", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3141c9df36dda9e484746d33ff3c0628f7471c35
kalyanam-FMTGA/ray-original
src/util/dctimestep.c
[ "BSD-3-Clause-LBNL" ]
C
cm_scale
CMATRIX
static CMATRIX * cm_scale(const CMATRIX *cm1, const COLOR sca) { CMATRIX *cmr; int dr, dc; cmr = cm_alloc(cm1->nrows, cm1->ncols); if (cmr == NULL) return(NULL); for (dr = 0; dr < cmr->nrows; dr++) for (dc = 0; dc < cmr->ncols; dc++) { const COLORV *sp = cm_lval(cm1,dr,dc); COLORV *dp = cm_lval(cmr,dr,dc); dp[0] = sp[0] * sca[0]; dp[1] = sp[1] * sca[1]; dp[2] = sp[2] * sca[2]; } return(cmr); }
/* Scale a matrix by a single value */
Scale a matrix by a single value
[ "Scale", "a", "matrix", "by", "a", "single", "value" ]
static CMATRIX * cm_scale(const CMATRIX *cm1, const COLOR sca) { CMATRIX *cmr; int dr, dc; cmr = cm_alloc(cm1->nrows, cm1->ncols); if (cmr == NULL) return(NULL); for (dr = 0; dr < cmr->nrows; dr++) for (dc = 0; dc < cmr->ncols; dc++) { const COLORV *sp = cm_lval(cm1,dr,dc); COLORV *dp = cm_lval(cmr,dr,dc); dp[0] = sp[0] * sca[0]; dp[1] = sp[1] * sca[1]; dp[2] = sp[2] * sca[2]; } return(cmr); }
[ "static", "CMATRIX", "*", "cm_scale", "(", "const", "CMATRIX", "*", "cm1", ",", "const", "COLOR", "sca", ")", "{", "CMATRIX", "*", "cmr", ";", "int", "dr", ",", "dc", ";", "cmr", "=", "cm_alloc", "(", "cm1", "->", "nrows", ",", "cm1", "->", "ncols", ")", ";", "if", "(", "cmr", "==", "NULL", ")", "return", "(", "NULL", ")", ";", "for", "(", "dr", "=", "0", ";", "dr", "<", "cmr", "->", "nrows", ";", "dr", "++", ")", "for", "(", "dc", "=", "0", ";", "dc", "<", "cmr", "->", "ncols", ";", "dc", "++", ")", "{", "const", "COLORV", "*", "sp", "=", "cm_lval", "(", "cm1", ",", "dr", ",", "dc", ")", ";", "COLORV", "*", "dp", "=", "cm_lval", "(", "cmr", ",", "dr", ",", "dc", ")", ";", "dp", "[", "0", "]", "=", "sp", "[", "0", "]", "*", "sca", "[", "0", "]", ";", "dp", "[", "1", "]", "=", "sp", "[", "1", "]", "*", "sca", "[", "1", "]", ";", "dp", "[", "2", "]", "=", "sp", "[", "2", "]", "*", "sca", "[", "2", "]", ";", "}", "return", "(", "cmr", ")", ";", "}" ]
Scale a matrix by a single value
[ "Scale", "a", "matrix", "by", "a", "single", "value" ]
[]
[ { "param": "cm1", "type": "CMATRIX" }, { "param": "sca", "type": "COLOR" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "cm1", "type": "CMATRIX", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "sca", "type": "COLOR", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3141c9df36dda9e484746d33ff3c0628f7471c35
kalyanam-FMTGA/ray-original
src/util/dctimestep.c
[ "BSD-3-Clause-LBNL" ]
C
cm_multiply
CMATRIX
static CMATRIX * cm_multiply(const CMATRIX *cm1, const CMATRIX *cm2) { char *rowcheck=NULL, *colcheck=NULL; CMATRIX *cmr; int dr, dc, i; if ((cm1->ncols <= 0) | (cm1->ncols != cm2->nrows)) error(INTERNAL, "matrix dimension mismatch in cm_multiply()"); cmr = cm_alloc(cm1->nrows, cm2->ncols); if (cmr == NULL) return(NULL); /* optimization: check for zero rows & cols */ if (((cm1->nrows > 5) | (cm2->ncols > 5)) & (cm1->ncols > 5)) { static const COLOR czero; rowcheck = (char *)calloc(cmr->nrows, 1); for (dr = cm1->nrows*(rowcheck != NULL); dr--; ) for (dc = cm1->ncols; dc--; ) if (memcmp(cm_lval(cm1,dr,dc), czero, sizeof(COLOR))) { rowcheck[dr] = 1; break; } colcheck = (char *)calloc(cmr->ncols, 1); for (dc = cm2->ncols*(colcheck != NULL); dc--; ) for (dr = cm2->nrows; dr--; ) if (memcmp(cm_lval(cm2,dr,dc), czero, sizeof(COLOR))) { colcheck[dc] = 1; break; } } for (dr = 0; dr < cmr->nrows; dr++) for (dc = 0; dc < cmr->ncols; dc++) { COLORV *dp = cm_lval(cmr,dr,dc); dp[0] = dp[1] = dp[2] = 0; if (rowcheck != NULL && !rowcheck[dr]) continue; if (colcheck != NULL && !colcheck[dc]) continue; for (i = 0; i < cm1->ncols; i++) { const COLORV *cp1 = cm_lval(cm1,dr,i); const COLORV *cp2 = cm_lval(cm2,i,dc); dp[0] += cp1[0] * cp2[0]; dp[1] += cp1[1] * cp2[1]; dp[2] += cp1[2] * cp2[2]; } } if (rowcheck != NULL) free(rowcheck); if (colcheck != NULL) free(colcheck); return(cmr); }
/* Multiply two matrices (or a matrix and a vector) and allocate the result */
Multiply two matrices (or a matrix and a vector) and allocate the result
[ "Multiply", "two", "matrices", "(", "or", "a", "matrix", "and", "a", "vector", ")", "and", "allocate", "the", "result" ]
static CMATRIX * cm_multiply(const CMATRIX *cm1, const CMATRIX *cm2) { char *rowcheck=NULL, *colcheck=NULL; CMATRIX *cmr; int dr, dc, i; if ((cm1->ncols <= 0) | (cm1->ncols != cm2->nrows)) error(INTERNAL, "matrix dimension mismatch in cm_multiply()"); cmr = cm_alloc(cm1->nrows, cm2->ncols); if (cmr == NULL) return(NULL); if (((cm1->nrows > 5) | (cm2->ncols > 5)) & (cm1->ncols > 5)) { static const COLOR czero; rowcheck = (char *)calloc(cmr->nrows, 1); for (dr = cm1->nrows*(rowcheck != NULL); dr--; ) for (dc = cm1->ncols; dc--; ) if (memcmp(cm_lval(cm1,dr,dc), czero, sizeof(COLOR))) { rowcheck[dr] = 1; break; } colcheck = (char *)calloc(cmr->ncols, 1); for (dc = cm2->ncols*(colcheck != NULL); dc--; ) for (dr = cm2->nrows; dr--; ) if (memcmp(cm_lval(cm2,dr,dc), czero, sizeof(COLOR))) { colcheck[dc] = 1; break; } } for (dr = 0; dr < cmr->nrows; dr++) for (dc = 0; dc < cmr->ncols; dc++) { COLORV *dp = cm_lval(cmr,dr,dc); dp[0] = dp[1] = dp[2] = 0; if (rowcheck != NULL && !rowcheck[dr]) continue; if (colcheck != NULL && !colcheck[dc]) continue; for (i = 0; i < cm1->ncols; i++) { const COLORV *cp1 = cm_lval(cm1,dr,i); const COLORV *cp2 = cm_lval(cm2,i,dc); dp[0] += cp1[0] * cp2[0]; dp[1] += cp1[1] * cp2[1]; dp[2] += cp1[2] * cp2[2]; } } if (rowcheck != NULL) free(rowcheck); if (colcheck != NULL) free(colcheck); return(cmr); }
[ "static", "CMATRIX", "*", "cm_multiply", "(", "const", "CMATRIX", "*", "cm1", ",", "const", "CMATRIX", "*", "cm2", ")", "{", "char", "*", "rowcheck", "=", "NULL", ",", "*", "colcheck", "=", "NULL", ";", "CMATRIX", "*", "cmr", ";", "int", "dr", ",", "dc", ",", "i", ";", "if", "(", "(", "cm1", "->", "ncols", "<=", "0", ")", "|", "(", "cm1", "->", "ncols", "!=", "cm2", "->", "nrows", ")", ")", "error", "(", "INTERNAL", ",", "\"", "\"", ")", ";", "cmr", "=", "cm_alloc", "(", "cm1", "->", "nrows", ",", "cm2", "->", "ncols", ")", ";", "if", "(", "cmr", "==", "NULL", ")", "return", "(", "NULL", ")", ";", "if", "(", "(", "(", "cm1", "->", "nrows", ">", "5", ")", "|", "(", "cm2", "->", "ncols", ">", "5", ")", ")", "&", "(", "cm1", "->", "ncols", ">", "5", ")", ")", "{", "static", "const", "COLOR", "czero", ";", "rowcheck", "=", "(", "char", "*", ")", "calloc", "(", "cmr", "->", "nrows", ",", "1", ")", ";", "for", "(", "dr", "=", "cm1", "->", "nrows", "*", "(", "rowcheck", "!=", "NULL", ")", ";", "dr", "--", ";", ")", "for", "(", "dc", "=", "cm1", "->", "ncols", ";", "dc", "--", ";", ")", "if", "(", "memcmp", "(", "cm_lval", "(", "cm1", ",", "dr", ",", "dc", ")", ",", "czero", ",", "sizeof", "(", "COLOR", ")", ")", ")", "{", "rowcheck", "[", "dr", "]", "=", "1", ";", "break", ";", "}", "colcheck", "=", "(", "char", "*", ")", "calloc", "(", "cmr", "->", "ncols", ",", "1", ")", ";", "for", "(", "dc", "=", "cm2", "->", "ncols", "*", "(", "colcheck", "!=", "NULL", ")", ";", "dc", "--", ";", ")", "for", "(", "dr", "=", "cm2", "->", "nrows", ";", "dr", "--", ";", ")", "if", "(", "memcmp", "(", "cm_lval", "(", "cm2", ",", "dr", ",", "dc", ")", ",", "czero", ",", "sizeof", "(", "COLOR", ")", ")", ")", "{", "colcheck", "[", "dc", "]", "=", "1", ";", "break", ";", "}", "}", "for", "(", "dr", "=", "0", ";", "dr", "<", "cmr", "->", "nrows", ";", "dr", "++", ")", "for", "(", "dc", "=", "0", ";", "dc", "<", "cmr", "->", "ncols", ";", "dc", "++", ")", "{", "COLORV", "*", "dp", "=", "cm_lval", "(", "cmr", ",", "dr", ",", "dc", ")", ";", "dp", "[", "0", "]", "=", "dp", "[", "1", "]", "=", "dp", "[", "2", "]", "=", "0", ";", "if", "(", "rowcheck", "!=", "NULL", "&&", "!", "rowcheck", "[", "dr", "]", ")", "continue", ";", "if", "(", "colcheck", "!=", "NULL", "&&", "!", "colcheck", "[", "dc", "]", ")", "continue", ";", "for", "(", "i", "=", "0", ";", "i", "<", "cm1", "->", "ncols", ";", "i", "++", ")", "{", "const", "COLORV", "*", "cp1", "=", "cm_lval", "(", "cm1", ",", "dr", ",", "i", ")", ";", "const", "COLORV", "*", "cp2", "=", "cm_lval", "(", "cm2", ",", "i", ",", "dc", ")", ";", "dp", "[", "0", "]", "+=", "cp1", "[", "0", "]", "*", "cp2", "[", "0", "]", ";", "dp", "[", "1", "]", "+=", "cp1", "[", "1", "]", "*", "cp2", "[", "1", "]", ";", "dp", "[", "2", "]", "+=", "cp1", "[", "2", "]", "*", "cp2", "[", "2", "]", ";", "}", "}", "if", "(", "rowcheck", "!=", "NULL", ")", "free", "(", "rowcheck", ")", ";", "if", "(", "colcheck", "!=", "NULL", ")", "free", "(", "colcheck", ")", ";", "return", "(", "cmr", ")", ";", "}" ]
Multiply two matrices (or a matrix and a vector) and allocate the result
[ "Multiply", "two", "matrices", "(", "or", "a", "matrix", "and", "a", "vector", ")", "and", "allocate", "the", "result" ]
[ "/* optimization: check for zero rows & cols */" ]
[ { "param": "cm1", "type": "CMATRIX" }, { "param": "cm2", "type": "CMATRIX" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "cm1", "type": "CMATRIX", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cm2", "type": "CMATRIX", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3141c9df36dda9e484746d33ff3c0628f7471c35
kalyanam-FMTGA/ray-original
src/util/dctimestep.c
[ "BSD-3-Clause-LBNL" ]
C
cm_print
void
static void cm_print(const CMATRIX *cm, FILE *fp) { int r, c; const COLORV *mp = cm->cmem; for (r = 0; r < cm->nrows; r++) { for (c = 0; c < cm->ncols; c++, mp += 3) fprintf(fp, "\t%.6e %.6e %.6e", mp[0], mp[1], mp[2]); fputc('\n', fp); } }
/* print out matrix as ASCII text -- no header */
print out matrix as ASCII text -- no header
[ "print", "out", "matrix", "as", "ASCII", "text", "--", "no", "header" ]
static void cm_print(const CMATRIX *cm, FILE *fp) { int r, c; const COLORV *mp = cm->cmem; for (r = 0; r < cm->nrows; r++) { for (c = 0; c < cm->ncols; c++, mp += 3) fprintf(fp, "\t%.6e %.6e %.6e", mp[0], mp[1], mp[2]); fputc('\n', fp); } }
[ "static", "void", "cm_print", "(", "const", "CMATRIX", "*", "cm", ",", "FILE", "*", "fp", ")", "{", "int", "r", ",", "c", ";", "const", "COLORV", "*", "mp", "=", "cm", "->", "cmem", ";", "for", "(", "r", "=", "0", ";", "r", "<", "cm", "->", "nrows", ";", "r", "++", ")", "{", "for", "(", "c", "=", "0", ";", "c", "<", "cm", "->", "ncols", ";", "c", "++", ",", "mp", "+=", "3", ")", "fprintf", "(", "fp", ",", "\"", "\\t", "\"", ",", "mp", "[", "0", "]", ",", "mp", "[", "1", "]", ",", "mp", "[", "2", "]", ")", ";", "fputc", "(", "'", "\\n", "'", ",", "fp", ")", ";", "}", "}" ]
print out matrix as ASCII text -- no header
[ "print", "out", "matrix", "as", "ASCII", "text", "--", "no", "header" ]
[]
[ { "param": "cm", "type": "CMATRIX" }, { "param": "fp", "type": "FILE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "cm", "type": "CMATRIX", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "fp", "type": "FILE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3141c9df36dda9e484746d33ff3c0628f7471c35
kalyanam-FMTGA/ray-original
src/util/dctimestep.c
[ "BSD-3-Clause-LBNL" ]
C
cm_bsdf
CMATRIX
static CMATRIX * cm_bsdf(const COLOR bsdfLamb, const COLOR specCol, const SDMat *bsdf) { CMATRIX *cm = cm_alloc(bsdf->nout, bsdf->ninc); int nbadohm = 0; int nneg = 0; int r, c; /* loop over incident angles */ for (c = 0; c < cm->ncols; c++) { const double dom = mBSDF_incohm(bsdf,c); /* projected solid angle */ nbadohm += (dom <= 0); for (r = 0; r < cm->nrows; r++) { float f = mBSDF_value(bsdf,c,r); COLORV *mp = cm_lval(cm,r,c); /* check BSDF value */ if ((f <= 0) | (dom <= 0)) { nneg += (f < -FTINY); f = .0f; } copycolor(mp, specCol); scalecolor(mp, f); addcolor(mp, bsdfLamb); scalecolor(mp, dom); } } if (nneg | nbadohm) { sprintf(errmsg, "BTDF has %d negatives and %d bad incoming solid angles", nneg, nbadohm); error(WARNING, errmsg); } return(cm); }
/* Convert a BSDF to our matrix representation */
Convert a BSDF to our matrix representation
[ "Convert", "a", "BSDF", "to", "our", "matrix", "representation" ]
static CMATRIX * cm_bsdf(const COLOR bsdfLamb, const COLOR specCol, const SDMat *bsdf) { CMATRIX *cm = cm_alloc(bsdf->nout, bsdf->ninc); int nbadohm = 0; int nneg = 0; int r, c; for (c = 0; c < cm->ncols; c++) { const double dom = mBSDF_incohm(bsdf,c); nbadohm += (dom <= 0); for (r = 0; r < cm->nrows; r++) { float f = mBSDF_value(bsdf,c,r); COLORV *mp = cm_lval(cm,r,c); if ((f <= 0) | (dom <= 0)) { nneg += (f < -FTINY); f = .0f; } copycolor(mp, specCol); scalecolor(mp, f); addcolor(mp, bsdfLamb); scalecolor(mp, dom); } } if (nneg | nbadohm) { sprintf(errmsg, "BTDF has %d negatives and %d bad incoming solid angles", nneg, nbadohm); error(WARNING, errmsg); } return(cm); }
[ "static", "CMATRIX", "*", "cm_bsdf", "(", "const", "COLOR", "bsdfLamb", ",", "const", "COLOR", "specCol", ",", "const", "SDMat", "*", "bsdf", ")", "{", "CMATRIX", "*", "cm", "=", "cm_alloc", "(", "bsdf", "->", "nout", ",", "bsdf", "->", "ninc", ")", ";", "int", "nbadohm", "=", "0", ";", "int", "nneg", "=", "0", ";", "int", "r", ",", "c", ";", "for", "(", "c", "=", "0", ";", "c", "<", "cm", "->", "ncols", ";", "c", "++", ")", "{", "const", "double", "dom", "=", "mBSDF_incohm", "(", "bsdf", ",", "c", ")", ";", "nbadohm", "+=", "(", "dom", "<=", "0", ")", ";", "for", "(", "r", "=", "0", ";", "r", "<", "cm", "->", "nrows", ";", "r", "++", ")", "{", "float", "f", "=", "mBSDF_value", "(", "bsdf", ",", "c", ",", "r", ")", ";", "COLORV", "*", "mp", "=", "cm_lval", "(", "cm", ",", "r", ",", "c", ")", ";", "if", "(", "(", "f", "<=", "0", ")", "|", "(", "dom", "<=", "0", ")", ")", "{", "nneg", "+=", "(", "f", "<", "-", "FTINY", ")", ";", "f", "=", ".0f", ";", "}", "copycolor", "(", "mp", ",", "specCol", ")", ";", "scalecolor", "(", "mp", ",", "f", ")", ";", "addcolor", "(", "mp", ",", "bsdfLamb", ")", ";", "scalecolor", "(", "mp", ",", "dom", ")", ";", "}", "}", "if", "(", "nneg", "|", "nbadohm", ")", "{", "sprintf", "(", "errmsg", ",", "\"", "\"", ",", "nneg", ",", "nbadohm", ")", ";", "error", "(", "WARNING", ",", "errmsg", ")", ";", "}", "return", "(", "cm", ")", ";", "}" ]
Convert a BSDF to our matrix representation
[ "Convert", "a", "BSDF", "to", "our", "matrix", "representation" ]
[ "/* loop over incident angles */", "/* projected solid angle */", "/* check BSDF value */" ]
[ { "param": "bsdfLamb", "type": "COLOR" }, { "param": "specCol", "type": "COLOR" }, { "param": "bsdf", "type": "SDMat" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "bsdfLamb", "type": "COLOR", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "specCol", "type": "COLOR", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "bsdf", "type": "SDMat", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3141c9df36dda9e484746d33ff3c0628f7471c35
kalyanam-FMTGA/ray-original
src/util/dctimestep.c
[ "BSD-3-Clause-LBNL" ]
C
recip_out_from_in
int
static int recip_out_from_in(const SDMat *bsdf, int in_recip) { FVECT v; if (!mBSDF_incvec(v, bsdf, in_recip+.5)) return(in_recip); /* XXX should be error! */ v[2] = -v[2]; return(mBSDF_outndx(bsdf, v)); }
/* Convert between input and output indices for reciprocity */
Convert between input and output indices for reciprocity
[ "Convert", "between", "input", "and", "output", "indices", "for", "reciprocity" ]
static int recip_out_from_in(const SDMat *bsdf, int in_recip) { FVECT v; if (!mBSDF_incvec(v, bsdf, in_recip+.5)) return(in_recip); v[2] = -v[2]; return(mBSDF_outndx(bsdf, v)); }
[ "static", "int", "recip_out_from_in", "(", "const", "SDMat", "*", "bsdf", ",", "int", "in_recip", ")", "{", "FVECT", "v", ";", "if", "(", "!", "mBSDF_incvec", "(", "v", ",", "bsdf", ",", "in_recip", "+", ".5", ")", ")", "return", "(", "in_recip", ")", ";", "v", "[", "2", "]", "=", "-", "v", "[", "2", "]", ";", "return", "(", "mBSDF_outndx", "(", "bsdf", ",", "v", ")", ")", ";", "}" ]
Convert between input and output indices for reciprocity
[ "Convert", "between", "input", "and", "output", "indices", "for", "reciprocity" ]
[ "/* XXX should be error! */" ]
[ { "param": "bsdf", "type": "SDMat" }, { "param": "in_recip", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "bsdf", "type": "SDMat", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "in_recip", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3141c9df36dda9e484746d33ff3c0628f7471c35
kalyanam-FMTGA/ray-original
src/util/dctimestep.c
[ "BSD-3-Clause-LBNL" ]
C
recip_in_from_out
int
static int recip_in_from_out(const SDMat *bsdf, int out_recip) { FVECT v; if (!mBSDF_outvec(v, bsdf, out_recip+.5)) return(out_recip); /* XXX should be error! */ v[2] = -v[2]; return(mBSDF_incndx(bsdf, v)); }
/* Convert between output and input indices for reciprocity */
Convert between output and input indices for reciprocity
[ "Convert", "between", "output", "and", "input", "indices", "for", "reciprocity" ]
static int recip_in_from_out(const SDMat *bsdf, int out_recip) { FVECT v; if (!mBSDF_outvec(v, bsdf, out_recip+.5)) return(out_recip); v[2] = -v[2]; return(mBSDF_incndx(bsdf, v)); }
[ "static", "int", "recip_in_from_out", "(", "const", "SDMat", "*", "bsdf", ",", "int", "out_recip", ")", "{", "FVECT", "v", ";", "if", "(", "!", "mBSDF_outvec", "(", "v", ",", "bsdf", ",", "out_recip", "+", ".5", ")", ")", "return", "(", "out_recip", ")", ";", "v", "[", "2", "]", "=", "-", "v", "[", "2", "]", ";", "return", "(", "mBSDF_incndx", "(", "bsdf", ",", "v", ")", ")", ";", "}" ]
Convert between output and input indices for reciprocity
[ "Convert", "between", "output", "and", "input", "indices", "for", "reciprocity" ]
[ "/* XXX should be error! */" ]
[ { "param": "bsdf", "type": "SDMat" }, { "param": "out_recip", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "bsdf", "type": "SDMat", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "out_recip", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3141c9df36dda9e484746d33ff3c0628f7471c35
kalyanam-FMTGA/ray-original
src/util/dctimestep.c
[ "BSD-3-Clause-LBNL" ]
C
cm_bsdf_recip
CMATRIX
static CMATRIX * cm_bsdf_recip(const COLOR bsdfLamb, const COLOR specCol, const SDMat *bsdf) { CMATRIX *cm = cm_alloc(bsdf->ninc, bsdf->nout); int nbadohm = 0; int nneg = 0; int r, c; /* loop over incident angles */ for (c = 0; c < cm->ncols; c++) { const int ro = recip_out_from_in(bsdf,c); const double dom = mBSDF_outohm(bsdf,ro); /* projected solid angle */ nbadohm += (dom <= 0); for (r = 0; r < cm->nrows; r++) { const int ri = recip_in_from_out(bsdf,r); float f = mBSDF_value(bsdf,ri,ro); COLORV *mp = cm_lval(cm,r,c); /* check BSDF value */ if ((f <= 0) | (dom <= 0)) { nneg += (f < -FTINY); f = .0f; } copycolor(mp, specCol); scalecolor(mp, f); addcolor(mp, bsdfLamb); scalecolor(mp, dom); } } if (nneg | nbadohm) { sprintf(errmsg, "BTDF has %d negatives and %d bad incoming solid angles", nneg, nbadohm); error(WARNING, errmsg); } return(cm); }
/* Convert a BSDF to our matrix representation, applying reciprocity */
Convert a BSDF to our matrix representation, applying reciprocity
[ "Convert", "a", "BSDF", "to", "our", "matrix", "representation", "applying", "reciprocity" ]
static CMATRIX * cm_bsdf_recip(const COLOR bsdfLamb, const COLOR specCol, const SDMat *bsdf) { CMATRIX *cm = cm_alloc(bsdf->ninc, bsdf->nout); int nbadohm = 0; int nneg = 0; int r, c; for (c = 0; c < cm->ncols; c++) { const int ro = recip_out_from_in(bsdf,c); const double dom = mBSDF_outohm(bsdf,ro); nbadohm += (dom <= 0); for (r = 0; r < cm->nrows; r++) { const int ri = recip_in_from_out(bsdf,r); float f = mBSDF_value(bsdf,ri,ro); COLORV *mp = cm_lval(cm,r,c); if ((f <= 0) | (dom <= 0)) { nneg += (f < -FTINY); f = .0f; } copycolor(mp, specCol); scalecolor(mp, f); addcolor(mp, bsdfLamb); scalecolor(mp, dom); } } if (nneg | nbadohm) { sprintf(errmsg, "BTDF has %d negatives and %d bad incoming solid angles", nneg, nbadohm); error(WARNING, errmsg); } return(cm); }
[ "static", "CMATRIX", "*", "cm_bsdf_recip", "(", "const", "COLOR", "bsdfLamb", ",", "const", "COLOR", "specCol", ",", "const", "SDMat", "*", "bsdf", ")", "{", "CMATRIX", "*", "cm", "=", "cm_alloc", "(", "bsdf", "->", "ninc", ",", "bsdf", "->", "nout", ")", ";", "int", "nbadohm", "=", "0", ";", "int", "nneg", "=", "0", ";", "int", "r", ",", "c", ";", "for", "(", "c", "=", "0", ";", "c", "<", "cm", "->", "ncols", ";", "c", "++", ")", "{", "const", "int", "ro", "=", "recip_out_from_in", "(", "bsdf", ",", "c", ")", ";", "const", "double", "dom", "=", "mBSDF_outohm", "(", "bsdf", ",", "ro", ")", ";", "nbadohm", "+=", "(", "dom", "<=", "0", ")", ";", "for", "(", "r", "=", "0", ";", "r", "<", "cm", "->", "nrows", ";", "r", "++", ")", "{", "const", "int", "ri", "=", "recip_in_from_out", "(", "bsdf", ",", "r", ")", ";", "float", "f", "=", "mBSDF_value", "(", "bsdf", ",", "ri", ",", "ro", ")", ";", "COLORV", "*", "mp", "=", "cm_lval", "(", "cm", ",", "r", ",", "c", ")", ";", "if", "(", "(", "f", "<=", "0", ")", "|", "(", "dom", "<=", "0", ")", ")", "{", "nneg", "+=", "(", "f", "<", "-", "FTINY", ")", ";", "f", "=", ".0f", ";", "}", "copycolor", "(", "mp", ",", "specCol", ")", ";", "scalecolor", "(", "mp", ",", "f", ")", ";", "addcolor", "(", "mp", ",", "bsdfLamb", ")", ";", "scalecolor", "(", "mp", ",", "dom", ")", ";", "}", "}", "if", "(", "nneg", "|", "nbadohm", ")", "{", "sprintf", "(", "errmsg", ",", "\"", "\"", ",", "nneg", ",", "nbadohm", ")", ";", "error", "(", "WARNING", ",", "errmsg", ")", ";", "}", "return", "(", "cm", ")", ";", "}" ]
Convert a BSDF to our matrix representation, applying reciprocity
[ "Convert", "a", "BSDF", "to", "our", "matrix", "representation", "applying", "reciprocity" ]
[ "/* loop over incident angles */", "/* projected solid angle */", "/* check BSDF value */" ]
[ { "param": "bsdfLamb", "type": "COLOR" }, { "param": "specCol", "type": "COLOR" }, { "param": "bsdf", "type": "SDMat" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "bsdfLamb", "type": "COLOR", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "specCol", "type": "COLOR", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "bsdf", "type": "SDMat", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3141c9df36dda9e484746d33ff3c0628f7471c35
kalyanam-FMTGA/ray-original
src/util/dctimestep.c
[ "BSD-3-Clause-LBNL" ]
C
cm_loadBSDF
CMATRIX
static CMATRIX * cm_loadBSDF(char *fname, COLOR cLamb) { CMATRIX *Tmat; char *fpath; int recip; SDError ec; SDData myBSDF; SDSpectralDF *tdf; COLOR bsdfLamb, specCol; /* find path to BSDF file */ fpath = getpath(fname, getrlibpath(), R_OK); if (fpath == NULL) { sprintf(errmsg, "cannot find BSDF file '%s'", fname); error(USER, errmsg); } SDclearBSDF(&myBSDF, fname); /* load XML and check type */ ec = SDloadFile(&myBSDF, fpath); if (ec) error(USER, transSDError(ec)); ccy2rgb(&myBSDF.tLamb.spec, myBSDF.tLamb.cieY/PI, bsdfLamb); recip = (myBSDF.tb == NULL); tdf = recip ? myBSDF.tf : myBSDF.tb; if (tdf == NULL) { /* no non-Lambertian transmission? */ if (cLamb != NULL) copycolor(cLamb, bsdfLamb); SDfreeBSDF(&myBSDF); return(NULL); } if (tdf->ncomp != 1 || tdf->comp[0].func != &SDhandleMtx) { sprintf(errmsg, "unsupported BSDF '%s'", fpath); error(USER, errmsg); } /* convert BTDF to matrix */ ccy2rgb(&tdf->comp[0].cspec[0], 1., specCol); Tmat = recip ? cm_bsdf_recip(bsdfLamb, specCol, (SDMat *)tdf->comp[0].dist) : cm_bsdf(bsdfLamb, specCol, (SDMat *)tdf->comp[0].dist); if (cLamb != NULL) /* Lambertian is included */ setcolor(cLamb, .0, .0, .0); /* free BSDF and return */ SDfreeBSDF(&myBSDF); return(Tmat); }
/* Load and convert a matrix BSDF from the given XML file */
Load and convert a matrix BSDF from the given XML file
[ "Load", "and", "convert", "a", "matrix", "BSDF", "from", "the", "given", "XML", "file" ]
static CMATRIX * cm_loadBSDF(char *fname, COLOR cLamb) { CMATRIX *Tmat; char *fpath; int recip; SDError ec; SDData myBSDF; SDSpectralDF *tdf; COLOR bsdfLamb, specCol; fpath = getpath(fname, getrlibpath(), R_OK); if (fpath == NULL) { sprintf(errmsg, "cannot find BSDF file '%s'", fname); error(USER, errmsg); } SDclearBSDF(&myBSDF, fname); ec = SDloadFile(&myBSDF, fpath); if (ec) error(USER, transSDError(ec)); ccy2rgb(&myBSDF.tLamb.spec, myBSDF.tLamb.cieY/PI, bsdfLamb); recip = (myBSDF.tb == NULL); tdf = recip ? myBSDF.tf : myBSDF.tb; if (tdf == NULL) { if (cLamb != NULL) copycolor(cLamb, bsdfLamb); SDfreeBSDF(&myBSDF); return(NULL); } if (tdf->ncomp != 1 || tdf->comp[0].func != &SDhandleMtx) { sprintf(errmsg, "unsupported BSDF '%s'", fpath); error(USER, errmsg); } ccy2rgb(&tdf->comp[0].cspec[0], 1., specCol); Tmat = recip ? cm_bsdf_recip(bsdfLamb, specCol, (SDMat *)tdf->comp[0].dist) : cm_bsdf(bsdfLamb, specCol, (SDMat *)tdf->comp[0].dist); if (cLamb != NULL) setcolor(cLamb, .0, .0, .0); SDfreeBSDF(&myBSDF); return(Tmat); }
[ "static", "CMATRIX", "*", "cm_loadBSDF", "(", "char", "*", "fname", ",", "COLOR", "cLamb", ")", "{", "CMATRIX", "*", "Tmat", ";", "char", "*", "fpath", ";", "int", "recip", ";", "SDError", "ec", ";", "SDData", "myBSDF", ";", "SDSpectralDF", "*", "tdf", ";", "COLOR", "bsdfLamb", ",", "specCol", ";", "fpath", "=", "getpath", "(", "fname", ",", "getrlibpath", "(", ")", ",", "R_OK", ")", ";", "if", "(", "fpath", "==", "NULL", ")", "{", "sprintf", "(", "errmsg", ",", "\"", "\"", ",", "fname", ")", ";", "error", "(", "USER", ",", "errmsg", ")", ";", "}", "SDclearBSDF", "(", "&", "myBSDF", ",", "fname", ")", ";", "ec", "=", "SDloadFile", "(", "&", "myBSDF", ",", "fpath", ")", ";", "if", "(", "ec", ")", "error", "(", "USER", ",", "transSDError", "(", "ec", ")", ")", ";", "ccy2rgb", "(", "&", "myBSDF", ".", "tLamb", ".", "spec", ",", "myBSDF", ".", "tLamb", ".", "cieY", "/", "PI", ",", "bsdfLamb", ")", ";", "recip", "=", "(", "myBSDF", ".", "tb", "==", "NULL", ")", ";", "tdf", "=", "recip", "?", "myBSDF", ".", "tf", ":", "myBSDF", ".", "tb", ";", "if", "(", "tdf", "==", "NULL", ")", "{", "if", "(", "cLamb", "!=", "NULL", ")", "copycolor", "(", "cLamb", ",", "bsdfLamb", ")", ";", "SDfreeBSDF", "(", "&", "myBSDF", ")", ";", "return", "(", "NULL", ")", ";", "}", "if", "(", "tdf", "->", "ncomp", "!=", "1", "||", "tdf", "->", "comp", "[", "0", "]", ".", "func", "!=", "&", "SDhandleMtx", ")", "{", "sprintf", "(", "errmsg", ",", "\"", "\"", ",", "fpath", ")", ";", "error", "(", "USER", ",", "errmsg", ")", ";", "}", "ccy2rgb", "(", "&", "tdf", "->", "comp", "[", "0", "]", ".", "cspec", "[", "0", "]", ",", "1.", ",", "specCol", ")", ";", "Tmat", "=", "recip", "?", "cm_bsdf_recip", "(", "bsdfLamb", ",", "specCol", ",", "(", "SDMat", "*", ")", "tdf", "->", "comp", "[", "0", "]", ".", "dist", ")", ":", "cm_bsdf", "(", "bsdfLamb", ",", "specCol", ",", "(", "SDMat", "*", ")", "tdf", "->", "comp", "[", "0", "]", ".", "dist", ")", ";", "if", "(", "cLamb", "!=", "NULL", ")", "setcolor", "(", "cLamb", ",", ".0", ",", ".0", ",", ".0", ")", ";", "SDfreeBSDF", "(", "&", "myBSDF", ")", ";", "return", "(", "Tmat", ")", ";", "}" ]
Load and convert a matrix BSDF from the given XML file
[ "Load", "and", "convert", "a", "matrix", "BSDF", "from", "the", "given", "XML", "file" ]
[ "/* find path to BSDF file */", "/* load XML and check type */", "/* no non-Lambertian transmission? */", "/* convert BTDF to matrix */", "/* Lambertian is included */", "/* free BSDF and return */" ]
[ { "param": "fname", "type": "char" }, { "param": "cLamb", "type": "COLOR" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fname", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cLamb", "type": "COLOR", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3141c9df36dda9e484746d33ff3c0628f7471c35
kalyanam-FMTGA/ray-original
src/util/dctimestep.c
[ "BSD-3-Clause-LBNL" ]
C
sum_images
int
static int sum_images(const char *fspec, const CMATRIX *cv, FILE *fout) { int myDT = DTfromHeader; COLOR *scanline = NULL; CMATRIX *pmat = NULL; int myXR=0, myYR=0; int i, y; if (cv->ncols != 1) error(INTERNAL, "expected vector in sum_images()"); for (i = 0; i < cv->nrows; i++) { const COLORV *scv = cv_lval(cv,i); char fname[1024]; FILE *fp; int dt, xr, yr; COLORV *psp; /* check for zero */ if ((scv[RED] == 0) & (scv[GRN] == 0) & (scv[BLU] == 0) && (myDT != DTfromHeader) | (i < cv->nrows-1)) continue; /* open next picture */ sprintf(fname, fspec, i); if ((fp = fopen(fname, "r")) == NULL) { sprintf(errmsg, "cannot open picture '%s'", fname); error(SYSTEM, errmsg); } SET_FILE_BINARY(fp); dt = getDTfromHeader(fp); if ((dt != DTrgbe) & (dt != DTxyze) || !fscnresolu(&xr, &yr, fp)) { sprintf(errmsg, "file '%s' not a picture", fname); error(USER, errmsg); } if (myDT == DTfromHeader) { /* on first one */ myDT = dt; myXR = xr; myYR = yr; scanline = (COLOR *)malloc(sizeof(COLOR)*myXR); if (scanline == NULL) error(SYSTEM, "out of memory in sum_images()"); pmat = cm_alloc(myYR, myXR); memset(pmat->cmem, 0, sizeof(COLOR)*myXR*myYR); /* finish header */ fputformat(myDT==DTrgbe ? COLRFMT : CIEFMT, fout); fputc('\n', fout); fprtresolu(myXR, myYR, fout); fflush(fout); } else if ((dt != myDT) | (xr != myXR) | (yr != myYR)) { sprintf(errmsg, "picture '%s' format/size mismatch", fname); error(USER, errmsg); } psp = pmat->cmem; for (y = 0; y < yr; y++) { /* read it in */ int x; if (freadscan(scanline, xr, fp) < 0) { sprintf(errmsg, "error reading picture '%s'", fname); error(SYSTEM, errmsg); } /* sum in scanline */ for (x = 0; x < xr; x++, psp += 3) { multcolor(scanline[x], scv); addcolor(psp, scanline[x]); } } fclose(fp); /* done this picture */ } free(scanline); /* write scanlines */ for (y = 0; y < myYR; y++) if (fwritescan((COLOR *)cm_lval(pmat, y, 0), myXR, fout) < 0) return(0); cm_free(pmat); /* all done */ return(fflush(fout) == 0); }
/* Sum together a set of images and write result to fout */
Sum together a set of images and write result to fout
[ "Sum", "together", "a", "set", "of", "images", "and", "write", "result", "to", "fout" ]
static int sum_images(const char *fspec, const CMATRIX *cv, FILE *fout) { int myDT = DTfromHeader; COLOR *scanline = NULL; CMATRIX *pmat = NULL; int myXR=0, myYR=0; int i, y; if (cv->ncols != 1) error(INTERNAL, "expected vector in sum_images()"); for (i = 0; i < cv->nrows; i++) { const COLORV *scv = cv_lval(cv,i); char fname[1024]; FILE *fp; int dt, xr, yr; COLORV *psp; if ((scv[RED] == 0) & (scv[GRN] == 0) & (scv[BLU] == 0) && (myDT != DTfromHeader) | (i < cv->nrows-1)) continue; sprintf(fname, fspec, i); if ((fp = fopen(fname, "r")) == NULL) { sprintf(errmsg, "cannot open picture '%s'", fname); error(SYSTEM, errmsg); } SET_FILE_BINARY(fp); dt = getDTfromHeader(fp); if ((dt != DTrgbe) & (dt != DTxyze) || !fscnresolu(&xr, &yr, fp)) { sprintf(errmsg, "file '%s' not a picture", fname); error(USER, errmsg); } if (myDT == DTfromHeader) { myDT = dt; myXR = xr; myYR = yr; scanline = (COLOR *)malloc(sizeof(COLOR)*myXR); if (scanline == NULL) error(SYSTEM, "out of memory in sum_images()"); pmat = cm_alloc(myYR, myXR); memset(pmat->cmem, 0, sizeof(COLOR)*myXR*myYR); fputformat(myDT==DTrgbe ? COLRFMT : CIEFMT, fout); fputc('\n', fout); fprtresolu(myXR, myYR, fout); fflush(fout); } else if ((dt != myDT) | (xr != myXR) | (yr != myYR)) { sprintf(errmsg, "picture '%s' format/size mismatch", fname); error(USER, errmsg); } psp = pmat->cmem; for (y = 0; y < yr; y++) { int x; if (freadscan(scanline, xr, fp) < 0) { sprintf(errmsg, "error reading picture '%s'", fname); error(SYSTEM, errmsg); } for (x = 0; x < xr; x++, psp += 3) { multcolor(scanline[x], scv); addcolor(psp, scanline[x]); } } fclose(fp); } free(scanline); for (y = 0; y < myYR; y++) if (fwritescan((COLOR *)cm_lval(pmat, y, 0), myXR, fout) < 0) return(0); cm_free(pmat); return(fflush(fout) == 0); }
[ "static", "int", "sum_images", "(", "const", "char", "*", "fspec", ",", "const", "CMATRIX", "*", "cv", ",", "FILE", "*", "fout", ")", "{", "int", "myDT", "=", "DTfromHeader", ";", "COLOR", "*", "scanline", "=", "NULL", ";", "CMATRIX", "*", "pmat", "=", "NULL", ";", "int", "myXR", "=", "0", ",", "myYR", "=", "0", ";", "int", "i", ",", "y", ";", "if", "(", "cv", "->", "ncols", "!=", "1", ")", "error", "(", "INTERNAL", ",", "\"", "\"", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "cv", "->", "nrows", ";", "i", "++", ")", "{", "const", "COLORV", "*", "scv", "=", "cv_lval", "(", "cv", ",", "i", ")", ";", "char", "fname", "[", "1024", "]", ";", "FILE", "*", "fp", ";", "int", "dt", ",", "xr", ",", "yr", ";", "COLORV", "*", "psp", ";", "if", "(", "(", "scv", "[", "RED", "]", "==", "0", ")", "&", "(", "scv", "[", "GRN", "]", "==", "0", ")", "&", "(", "scv", "[", "BLU", "]", "==", "0", ")", "&&", "(", "myDT", "!=", "DTfromHeader", ")", "|", "(", "i", "<", "cv", "->", "nrows", "-", "1", ")", ")", "continue", ";", "sprintf", "(", "fname", ",", "fspec", ",", "i", ")", ";", "if", "(", "(", "fp", "=", "fopen", "(", "fname", ",", "\"", "\"", ")", ")", "==", "NULL", ")", "{", "sprintf", "(", "errmsg", ",", "\"", "\"", ",", "fname", ")", ";", "error", "(", "SYSTEM", ",", "errmsg", ")", ";", "}", "SET_FILE_BINARY", "(", "fp", ")", ";", "dt", "=", "getDTfromHeader", "(", "fp", ")", ";", "if", "(", "(", "dt", "!=", "DTrgbe", ")", "&", "(", "dt", "!=", "DTxyze", ")", "||", "!", "fscnresolu", "(", "&", "xr", ",", "&", "yr", ",", "fp", ")", ")", "{", "sprintf", "(", "errmsg", ",", "\"", "\"", ",", "fname", ")", ";", "error", "(", "USER", ",", "errmsg", ")", ";", "}", "if", "(", "myDT", "==", "DTfromHeader", ")", "{", "myDT", "=", "dt", ";", "myXR", "=", "xr", ";", "myYR", "=", "yr", ";", "scanline", "=", "(", "COLOR", "*", ")", "malloc", "(", "sizeof", "(", "COLOR", ")", "*", "myXR", ")", ";", "if", "(", "scanline", "==", "NULL", ")", "error", "(", "SYSTEM", ",", "\"", "\"", ")", ";", "pmat", "=", "cm_alloc", "(", "myYR", ",", "myXR", ")", ";", "memset", "(", "pmat", "->", "cmem", ",", "0", ",", "sizeof", "(", "COLOR", ")", "*", "myXR", "*", "myYR", ")", ";", "fputformat", "(", "myDT", "==", "DTrgbe", "?", "COLRFMT", ":", "CIEFMT", ",", "fout", ")", ";", "fputc", "(", "'", "\\n", "'", ",", "fout", ")", ";", "fprtresolu", "(", "myXR", ",", "myYR", ",", "fout", ")", ";", "fflush", "(", "fout", ")", ";", "}", "else", "if", "(", "(", "dt", "!=", "myDT", ")", "|", "(", "xr", "!=", "myXR", ")", "|", "(", "yr", "!=", "myYR", ")", ")", "{", "sprintf", "(", "errmsg", ",", "\"", "\"", ",", "fname", ")", ";", "error", "(", "USER", ",", "errmsg", ")", ";", "}", "psp", "=", "pmat", "->", "cmem", ";", "for", "(", "y", "=", "0", ";", "y", "<", "yr", ";", "y", "++", ")", "{", "int", "x", ";", "if", "(", "freadscan", "(", "scanline", ",", "xr", ",", "fp", ")", "<", "0", ")", "{", "sprintf", "(", "errmsg", ",", "\"", "\"", ",", "fname", ")", ";", "error", "(", "SYSTEM", ",", "errmsg", ")", ";", "}", "for", "(", "x", "=", "0", ";", "x", "<", "xr", ";", "x", "++", ",", "psp", "+=", "3", ")", "{", "multcolor", "(", "scanline", "[", "x", "]", ",", "scv", ")", ";", "addcolor", "(", "psp", ",", "scanline", "[", "x", "]", ")", ";", "}", "}", "fclose", "(", "fp", ")", ";", "}", "free", "(", "scanline", ")", ";", "for", "(", "y", "=", "0", ";", "y", "<", "myYR", ";", "y", "++", ")", "if", "(", "fwritescan", "(", "(", "COLOR", "*", ")", "cm_lval", "(", "pmat", ",", "y", ",", "0", ")", ",", "myXR", ",", "fout", ")", "<", "0", ")", "return", "(", "0", ")", ";", "cm_free", "(", "pmat", ")", ";", "return", "(", "fflush", "(", "fout", ")", "==", "0", ")", ";", "}" ]
Sum together a set of images and write result to fout
[ "Sum", "together", "a", "set", "of", "images", "and", "write", "result", "to", "fout" ]
[ "/* check for zero */", "/* open next picture */", "/* on first one */", "/* finish header */", "/* read it in */", "/* sum in scanline */", "/* done this picture */", "/* write scanlines */", "/* all done */" ]
[ { "param": "fspec", "type": "char" }, { "param": "cv", "type": "CMATRIX" }, { "param": "fout", "type": "FILE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fspec", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cv", "type": "CMATRIX", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "fout", "type": "FILE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3141c9df36dda9e484746d33ff3c0628f7471c35
kalyanam-FMTGA/ray-original
src/util/dctimestep.c
[ "BSD-3-Clause-LBNL" ]
C
hasNumberFormat
int
static int hasNumberFormat(const char *s) { if (s == NULL) return(0); while (*s) { while (*s != '%') if (!*s++) return(0); if (*++s == '%') { /* ignore "%%" */ ++s; continue; } while (isdigit(*s)) /* field length */ ++s; /* field we'll use? */ if ((*s == 'd') | (*s == 'i') | (*s == 'o') | (*s == 'x') | (*s == 'X')) return(1); } return(0); /* didn't find one */ }
/* check to see if a string contains a %d or %o specification */
check to see if a string contains a %d or %o specification
[ "check", "to", "see", "if", "a", "string", "contains", "a", "%d", "or", "%o", "specification" ]
static int hasNumberFormat(const char *s) { if (s == NULL) return(0); while (*s) { while (*s != '%') if (!*s++) return(0); if (*++s == '%') { ++s; continue; } while (isdigit(*s)) ++s; if ((*s == 'd') | (*s == 'i') | (*s == 'o') | (*s == 'x') | (*s == 'X')) return(1); } return(0); }
[ "static", "int", "hasNumberFormat", "(", "const", "char", "*", "s", ")", "{", "if", "(", "s", "==", "NULL", ")", "return", "(", "0", ")", ";", "while", "(", "*", "s", ")", "{", "while", "(", "*", "s", "!=", "'", "'", ")", "if", "(", "!", "*", "s", "++", ")", "return", "(", "0", ")", ";", "if", "(", "*", "++", "s", "==", "'", "'", ")", "{", "++", "s", ";", "continue", ";", "}", "while", "(", "isdigit", "(", "*", "s", ")", ")", "++", "s", ";", "if", "(", "(", "*", "s", "==", "'", "'", ")", "|", "(", "*", "s", "==", "'", "'", ")", "|", "(", "*", "s", "==", "'", "'", ")", "|", "(", "*", "s", "==", "'", "'", ")", "|", "(", "*", "s", "==", "'", "'", ")", ")", "return", "(", "1", ")", ";", "}", "return", "(", "0", ")", ";", "}" ]
check to see if a string contains a %d or %o specification
[ "check", "to", "see", "if", "a", "string", "contains", "a", "%d", "or", "%o", "specification" ]
[ "/* ignore \"%%\" */", "/* field length */", "/* field we'll use? */", "/* didn't find one */" ]
[ { "param": "s", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "s", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
f6a43293d9f8bc18a91a1d32f420bed723144bd4
kalyanam-FMTGA/ray-original
src/common/disk2square.c
[ "BSD-3-Clause-LBNL" ]
C
SDdisk2square
void
void SDdisk2square(double sq[2], double diskx, double disky) { double r = sqrt( diskx*diskx + disky*disky ); double phi = atan2( disky, diskx ); double a, b; if (phi < -M_PI/4) phi += 2*M_PI; /* in range [-pi/4,7pi/4] */ if ( phi < M_PI/4) { /* region 1 */ a = r; b = phi * a / (M_PI/4); } else if ( phi < 3*M_PI/4 ) { /* region 2 */ b = r; a = -(phi - M_PI/2) * b / (M_PI/4); } else if ( phi < 5*M_PI/4 ) { /* region 3 */ a = -r; b = (phi - M_PI) * a / (M_PI/4); } else { /* region 4 */ b = -r; a = -(phi - 3*M_PI/2) * b / (M_PI/4); } sq[0] = (a + 1) * 0.5; sq[1] = (b + 1) * 0.5; }
/* Map point on unit disk to a unit square in [0,1]^2 range */
Map point on unit disk to a unit square in [0,1]^2 range
[ "Map", "point", "on", "unit", "disk", "to", "a", "unit", "square", "in", "[", "0", "1", "]", "^2", "range" ]
void SDdisk2square(double sq[2], double diskx, double disky) { double r = sqrt( diskx*diskx + disky*disky ); double phi = atan2( disky, diskx ); double a, b; if (phi < -M_PI/4) phi += 2*M_PI; if ( phi < M_PI/4) { a = r; b = phi * a / (M_PI/4); } else if ( phi < 3*M_PI/4 ) { b = r; a = -(phi - M_PI/2) * b / (M_PI/4); } else if ( phi < 5*M_PI/4 ) { a = -r; b = (phi - M_PI) * a / (M_PI/4); } else { b = -r; a = -(phi - 3*M_PI/2) * b / (M_PI/4); } sq[0] = (a + 1) * 0.5; sq[1] = (b + 1) * 0.5; }
[ "void", "SDdisk2square", "(", "double", "sq", "[", "2", "]", ",", "double", "diskx", ",", "double", "disky", ")", "{", "double", "r", "=", "sqrt", "(", "diskx", "*", "diskx", "+", "disky", "*", "disky", ")", ";", "double", "phi", "=", "atan2", "(", "disky", ",", "diskx", ")", ";", "double", "a", ",", "b", ";", "if", "(", "phi", "<", "-", "M_PI", "/", "4", ")", "phi", "+=", "2", "*", "M_PI", ";", "if", "(", "phi", "<", "M_PI", "/", "4", ")", "{", "a", "=", "r", ";", "b", "=", "phi", "*", "a", "/", "(", "M_PI", "/", "4", ")", ";", "}", "else", "if", "(", "phi", "<", "3", "*", "M_PI", "/", "4", ")", "{", "b", "=", "r", ";", "a", "=", "-", "(", "phi", "-", "M_PI", "/", "2", ")", "*", "b", "/", "(", "M_PI", "/", "4", ")", ";", "}", "else", "if", "(", "phi", "<", "5", "*", "M_PI", "/", "4", ")", "{", "a", "=", "-", "r", ";", "b", "=", "(", "phi", "-", "M_PI", ")", "*", "a", "/", "(", "M_PI", "/", "4", ")", ";", "}", "else", "{", "b", "=", "-", "r", ";", "a", "=", "-", "(", "phi", "-", "3", "*", "M_PI", "/", "2", ")", "*", "b", "/", "(", "M_PI", "/", "4", ")", ";", "}", "sq", "[", "0", "]", "=", "(", "a", "+", "1", ")", "*", "0.5", ";", "sq", "[", "1", "]", "=", "(", "b", "+", "1", ")", "*", "0.5", ";", "}" ]
Map point on unit disk to a unit square in [0,1]^2 range
[ "Map", "point", "on", "unit", "disk", "to", "a", "unit", "square", "in", "[", "0", "1", "]", "^2", "range" ]
[ "/* in range [-pi/4,7pi/4] */", "/* region 1 */", "/* region 2 */", "/* region 3 */", "/* region 4 */" ]
[ { "param": "sq", "type": "double" }, { "param": "diskx", "type": "double" }, { "param": "disky", "type": "double" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sq", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "diskx", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "disky", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4bb5b374f059baac02beac09c60ce273311b16cb
kalyanam-FMTGA/ray-original
src/px/neuclrtab.c
[ "BSD-3-Clause-LBNL" ]
C
inxbuild
void
static void inxbuild(void) { register int i,j,smallpos,smallval; register int *p,*q; int previouscol,startpos; previouscol = 0; startpos = 0; for (i=0; i<netsize; i++) { p = network[i]; smallpos = i; smallval = p[1]; /* index on g */ /* find smallest in i..netsize-1 */ for (j=i+1; j<netsize; j++) { q = network[j]; if (q[1] < smallval) { /* index on g */ smallpos = j; smallval = q[1]; /* index on g */ } } q = network[smallpos]; /* swap p (i) and q (smallpos) entries */ if (i != smallpos) { j = q[0]; q[0] = p[0]; p[0] = j; j = q[1]; q[1] = p[1]; p[1] = j; j = q[2]; q[2] = p[2]; p[2] = j; j = q[3]; q[3] = p[3]; p[3] = j; } /* smallval entry is now in position i */ if (smallval != previouscol) { netindex[previouscol] = (startpos+i)>>1; for (j=previouscol+1; j<smallval; j++) netindex[j] = i; previouscol = smallval; startpos = i; } } netindex[previouscol] = (startpos+maxnetpos)>>1; for (j=previouscol+1; j<256; j++) netindex[j] = maxnetpos; /* really 256 */ }
/* do after unbias - insertion sort of network and build netindex[0..255] */
do after unbias - insertion sort of network and build netindex[0..255]
[ "do", "after", "unbias", "-", "insertion", "sort", "of", "network", "and", "build", "netindex", "[", "0", "..", "255", "]" ]
static void inxbuild(void) { register int i,j,smallpos,smallval; register int *p,*q; int previouscol,startpos; previouscol = 0; startpos = 0; for (i=0; i<netsize; i++) { p = network[i]; smallpos = i; smallval = p[1]; for (j=i+1; j<netsize; j++) { q = network[j]; if (q[1] < smallval) { smallpos = j; smallval = q[1]; } } q = network[smallpos]; if (i != smallpos) { j = q[0]; q[0] = p[0]; p[0] = j; j = q[1]; q[1] = p[1]; p[1] = j; j = q[2]; q[2] = p[2]; p[2] = j; j = q[3]; q[3] = p[3]; p[3] = j; } if (smallval != previouscol) { netindex[previouscol] = (startpos+i)>>1; for (j=previouscol+1; j<smallval; j++) netindex[j] = i; previouscol = smallval; startpos = i; } } netindex[previouscol] = (startpos+maxnetpos)>>1; for (j=previouscol+1; j<256; j++) netindex[j] = maxnetpos; }
[ "static", "void", "inxbuild", "(", "void", ")", "{", "register", "int", "i", ",", "j", ",", "smallpos", ",", "smallval", ";", "register", "int", "*", "p", ",", "*", "q", ";", "int", "previouscol", ",", "startpos", ";", "previouscol", "=", "0", ";", "startpos", "=", "0", ";", "for", "(", "i", "=", "0", ";", "i", "<", "netsize", ";", "i", "++", ")", "{", "p", "=", "network", "[", "i", "]", ";", "smallpos", "=", "i", ";", "smallval", "=", "p", "[", "1", "]", ";", "for", "(", "j", "=", "i", "+", "1", ";", "j", "<", "netsize", ";", "j", "++", ")", "{", "q", "=", "network", "[", "j", "]", ";", "if", "(", "q", "[", "1", "]", "<", "smallval", ")", "{", "smallpos", "=", "j", ";", "smallval", "=", "q", "[", "1", "]", ";", "}", "}", "q", "=", "network", "[", "smallpos", "]", ";", "if", "(", "i", "!=", "smallpos", ")", "{", "j", "=", "q", "[", "0", "]", ";", "q", "[", "0", "]", "=", "p", "[", "0", "]", ";", "p", "[", "0", "]", "=", "j", ";", "j", "=", "q", "[", "1", "]", ";", "q", "[", "1", "]", "=", "p", "[", "1", "]", ";", "p", "[", "1", "]", "=", "j", ";", "j", "=", "q", "[", "2", "]", ";", "q", "[", "2", "]", "=", "p", "[", "2", "]", ";", "p", "[", "2", "]", "=", "j", ";", "j", "=", "q", "[", "3", "]", ";", "q", "[", "3", "]", "=", "p", "[", "3", "]", ";", "p", "[", "3", "]", "=", "j", ";", "}", "if", "(", "smallval", "!=", "previouscol", ")", "{", "netindex", "[", "previouscol", "]", "=", "(", "startpos", "+", "i", ")", ">>", "1", ";", "for", "(", "j", "=", "previouscol", "+", "1", ";", "j", "<", "smallval", ";", "j", "++", ")", "netindex", "[", "j", "]", "=", "i", ";", "previouscol", "=", "smallval", ";", "startpos", "=", "i", ";", "}", "}", "netindex", "[", "previouscol", "]", "=", "(", "startpos", "+", "maxnetpos", ")", ">>", "1", ";", "for", "(", "j", "=", "previouscol", "+", "1", ";", "j", "<", "256", ";", "j", "++", ")", "netindex", "[", "j", "]", "=", "maxnetpos", ";", "}" ]
do after unbias - insertion sort of network and build netindex[0..255]
[ "do", "after", "unbias", "-", "insertion", "sort", "of", "network", "and", "build", "netindex", "[", "0", "..", "255", "]" ]
[ "/* index on g */", "/* find smallest in i..netsize-1 */", "/* index on g */", "/* index on g */", "/* swap p (i) and q (smallpos) entries */", "/* smallval entry is now in position i */", "/* really 256 */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
4bb5b374f059baac02beac09c60ce273311b16cb
kalyanam-FMTGA/ray-original
src/px/neuclrtab.c
[ "BSD-3-Clause-LBNL" ]
C
unbiasnet
void
static void unbiasnet(void) { int i,j; for (i=0; i<netsize; i++) { for (j=0; j<3; j++) network[i][j] >>= netbiasshift; network[i][3] = i; /* record colour no */ } }
/* unbias network to give 0..255 entries */ /* which can then be used for colour map */ /* and record position i to prepare for sort */
unbias network to give 0..255 entries which can then be used for colour map and record position i to prepare for sort
[ "unbias", "network", "to", "give", "0", "..", "255", "entries", "which", "can", "then", "be", "used", "for", "colour", "map", "and", "record", "position", "i", "to", "prepare", "for", "sort" ]
static void unbiasnet(void) { int i,j; for (i=0; i<netsize; i++) { for (j=0; j<3; j++) network[i][j] >>= netbiasshift; network[i][3] = i; } }
[ "static", "void", "unbiasnet", "(", "void", ")", "{", "int", "i", ",", "j", ";", "for", "(", "i", "=", "0", ";", "i", "<", "netsize", ";", "i", "++", ")", "{", "for", "(", "j", "=", "0", ";", "j", "<", "3", ";", "j", "++", ")", "network", "[", "i", "]", "[", "j", "]", ">>=", "netbiasshift", ";", "network", "[", "i", "]", "[", "3", "]", "=", "i", ";", "}", "}" ]
unbias network to give 0..255 entries which can then be used for colour map and record position i to prepare for sort
[ "unbias", "network", "to", "give", "0", "..", "255", "entries", "which", "can", "then", "be", "used", "for", "colour", "map", "and", "record", "position", "i", "to", "prepare", "for", "sort" ]
[ "/* record colour no */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
4bb5b374f059baac02beac09c60ce273311b16cb
kalyanam-FMTGA/ray-original
src/px/neuclrtab.c
[ "BSD-3-Clause-LBNL" ]
C
cpyclrtab
void
static void cpyclrtab(void) { register int i,j,k; for (j=0; j<netsize; j++) { k = network[j][3]; for (i = 0; i < 3; i++) clrtab[k][i] = network[j][2-i]; } }
/* Don't do this until the network has been unbiased (GW) */
Don't do this until the network has been unbiased (GW)
[ "Don", "'", "t", "do", "this", "until", "the", "network", "has", "been", "unbiased", "(", "GW", ")" ]
static void cpyclrtab(void) { register int i,j,k; for (j=0; j<netsize; j++) { k = network[j][3]; for (i = 0; i < 3; i++) clrtab[k][i] = network[j][2-i]; } }
[ "static", "void", "cpyclrtab", "(", "void", ")", "{", "register", "int", "i", ",", "j", ",", "k", ";", "for", "(", "j", "=", "0", ";", "j", "<", "netsize", ";", "j", "++", ")", "{", "k", "=", "network", "[", "j", "]", "[", "3", "]", ";", "for", "(", "i", "=", "0", ";", "i", "<", "3", ";", "i", "++", ")", "clrtab", "[", "k", "]", "[", "i", "]", "=", "network", "[", "j", "]", "[", "2", "-", "i", "]", ";", "}", "}" ]
Don't do this until the network has been unbiased (GW)
[ "Don", "'", "t", "do", "this", "until", "the", "network", "has", "been", "unbiased", "(", "GW", ")" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
ed7d897efc67da1dd490cceb8eb92d3a14144940
kalyanam-FMTGA/ray-original
src/cv/bsdfinterp.c
[ "BSD-3-Clause-LBNL" ]
C
order_triangle
int
static int order_triangle(MIGRATION *miga[3]) { RBFNODE *vert[7]; MIGRATION *ord[3]; int i; /* order vertices, first */ memset(vert, 0, sizeof(vert)); for (i = 3; i--; ) { if (miga[i] == NULL) return(0); insert_vert(vert, miga[i]->rbfv[0]); insert_vert(vert, miga[i]->rbfv[1]); } /* should be just 3 vertices */ if ((vert[2] == NULL) | (vert[3] != NULL)) return(0); /* identify edge 0 */ for (i = 3; i--; ) if (miga[i]->rbfv[0] == vert[0] && miga[i]->rbfv[1] == vert[1]) { ord[0] = miga[i]; break; } if (i < 0) return(0); /* identify edge 1 */ for (i = 3; i--; ) if (miga[i]->rbfv[0] == vert[1] && miga[i]->rbfv[1] == vert[2]) { ord[1] = miga[i]; break; } if (i < 0) return(0); /* identify edge 2 */ for (i = 3; i--; ) if (miga[i]->rbfv[0] == vert[0] && miga[i]->rbfv[1] == vert[2]) { ord[2] = miga[i]; break; } if (i < 0) return(0); /* reassign order */ miga[0] = ord[0]; miga[1] = ord[1]; miga[2] = ord[2]; return(1); }
/* Sort triangle edges in standard order */
Sort triangle edges in standard order
[ "Sort", "triangle", "edges", "in", "standard", "order" ]
static int order_triangle(MIGRATION *miga[3]) { RBFNODE *vert[7]; MIGRATION *ord[3]; int i; memset(vert, 0, sizeof(vert)); for (i = 3; i--; ) { if (miga[i] == NULL) return(0); insert_vert(vert, miga[i]->rbfv[0]); insert_vert(vert, miga[i]->rbfv[1]); } if ((vert[2] == NULL) | (vert[3] != NULL)) return(0); for (i = 3; i--; ) if (miga[i]->rbfv[0] == vert[0] && miga[i]->rbfv[1] == vert[1]) { ord[0] = miga[i]; break; } if (i < 0) return(0); for (i = 3; i--; ) if (miga[i]->rbfv[0] == vert[1] && miga[i]->rbfv[1] == vert[2]) { ord[1] = miga[i]; break; } if (i < 0) return(0); for (i = 3; i--; ) if (miga[i]->rbfv[0] == vert[0] && miga[i]->rbfv[1] == vert[2]) { ord[2] = miga[i]; break; } if (i < 0) return(0); miga[0] = ord[0]; miga[1] = ord[1]; miga[2] = ord[2]; return(1); }
[ "static", "int", "order_triangle", "(", "MIGRATION", "*", "miga", "[", "3", "]", ")", "{", "RBFNODE", "*", "vert", "[", "7", "]", ";", "MIGRATION", "*", "ord", "[", "3", "]", ";", "int", "i", ";", "memset", "(", "vert", ",", "0", ",", "sizeof", "(", "vert", ")", ")", ";", "for", "(", "i", "=", "3", ";", "i", "--", ";", ")", "{", "if", "(", "miga", "[", "i", "]", "==", "NULL", ")", "return", "(", "0", ")", ";", "insert_vert", "(", "vert", ",", "miga", "[", "i", "]", "->", "rbfv", "[", "0", "]", ")", ";", "insert_vert", "(", "vert", ",", "miga", "[", "i", "]", "->", "rbfv", "[", "1", "]", ")", ";", "}", "if", "(", "(", "vert", "[", "2", "]", "==", "NULL", ")", "|", "(", "vert", "[", "3", "]", "!=", "NULL", ")", ")", "return", "(", "0", ")", ";", "for", "(", "i", "=", "3", ";", "i", "--", ";", ")", "if", "(", "miga", "[", "i", "]", "->", "rbfv", "[", "0", "]", "==", "vert", "[", "0", "]", "&&", "miga", "[", "i", "]", "->", "rbfv", "[", "1", "]", "==", "vert", "[", "1", "]", ")", "{", "ord", "[", "0", "]", "=", "miga", "[", "i", "]", ";", "break", ";", "}", "if", "(", "i", "<", "0", ")", "return", "(", "0", ")", ";", "for", "(", "i", "=", "3", ";", "i", "--", ";", ")", "if", "(", "miga", "[", "i", "]", "->", "rbfv", "[", "0", "]", "==", "vert", "[", "1", "]", "&&", "miga", "[", "i", "]", "->", "rbfv", "[", "1", "]", "==", "vert", "[", "2", "]", ")", "{", "ord", "[", "1", "]", "=", "miga", "[", "i", "]", ";", "break", ";", "}", "if", "(", "i", "<", "0", ")", "return", "(", "0", ")", ";", "for", "(", "i", "=", "3", ";", "i", "--", ";", ")", "if", "(", "miga", "[", "i", "]", "->", "rbfv", "[", "0", "]", "==", "vert", "[", "0", "]", "&&", "miga", "[", "i", "]", "->", "rbfv", "[", "1", "]", "==", "vert", "[", "2", "]", ")", "{", "ord", "[", "2", "]", "=", "miga", "[", "i", "]", ";", "break", ";", "}", "if", "(", "i", "<", "0", ")", "return", "(", "0", ")", ";", "miga", "[", "0", "]", "=", "ord", "[", "0", "]", ";", "miga", "[", "1", "]", "=", "ord", "[", "1", "]", ";", "miga", "[", "2", "]", "=", "ord", "[", "2", "]", ";", "return", "(", "1", ")", ";", "}" ]
Sort triangle edges in standard order
[ "Sort", "triangle", "edges", "in", "standard", "order" ]
[ "/* order vertices, first */", "/* should be just 3 vertices */", "/* identify edge 0 */", "/* identify edge 1 */", "/* identify edge 2 */", "/* reassign order */" ]
[ { "param": "miga", "type": "MIGRATION" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "miga", "type": "MIGRATION", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
ed7d897efc67da1dd490cceb8eb92d3a14144940
kalyanam-FMTGA/ray-original
src/cv/bsdfinterp.c
[ "BSD-3-Clause-LBNL" ]
C
on_edge
int
static int on_edge(const MIGRATION *ej, const FVECT ivec) { double cos_a, cos_b, cos_c, cos_aplusb; /* use triangle inequality */ cos_a = DOT(ej->rbfv[0]->invec, ivec); if (cos_a <= 0) return(0); cos_b = DOT(ej->rbfv[1]->invec, ivec); if (cos_b <= 0) return(0); cos_aplusb = cos_a*cos_b - sqrt((1.-cos_a*cos_a)*(1.-cos_b*cos_b)); if (cos_aplusb <= 0) return(0); cos_c = DOT(ej->rbfv[0]->invec, ej->rbfv[1]->invec); return(cos_c - cos_aplusb < .001); }
/* Determine if we are close enough to an edge */
Determine if we are close enough to an edge
[ "Determine", "if", "we", "are", "close", "enough", "to", "an", "edge" ]
static int on_edge(const MIGRATION *ej, const FVECT ivec) { double cos_a, cos_b, cos_c, cos_aplusb; cos_a = DOT(ej->rbfv[0]->invec, ivec); if (cos_a <= 0) return(0); cos_b = DOT(ej->rbfv[1]->invec, ivec); if (cos_b <= 0) return(0); cos_aplusb = cos_a*cos_b - sqrt((1.-cos_a*cos_a)*(1.-cos_b*cos_b)); if (cos_aplusb <= 0) return(0); cos_c = DOT(ej->rbfv[0]->invec, ej->rbfv[1]->invec); return(cos_c - cos_aplusb < .001); }
[ "static", "int", "on_edge", "(", "const", "MIGRATION", "*", "ej", ",", "const", "FVECT", "ivec", ")", "{", "double", "cos_a", ",", "cos_b", ",", "cos_c", ",", "cos_aplusb", ";", "cos_a", "=", "DOT", "(", "ej", "->", "rbfv", "[", "0", "]", "->", "invec", ",", "ivec", ")", ";", "if", "(", "cos_a", "<=", "0", ")", "return", "(", "0", ")", ";", "cos_b", "=", "DOT", "(", "ej", "->", "rbfv", "[", "1", "]", "->", "invec", ",", "ivec", ")", ";", "if", "(", "cos_b", "<=", "0", ")", "return", "(", "0", ")", ";", "cos_aplusb", "=", "cos_a", "*", "cos_b", "-", "sqrt", "(", "(", "1.", "-", "cos_a", "*", "cos_a", ")", "*", "(", "1.", "-", "cos_b", "*", "cos_b", ")", ")", ";", "if", "(", "cos_aplusb", "<=", "0", ")", "return", "(", "0", ")", ";", "cos_c", "=", "DOT", "(", "ej", "->", "rbfv", "[", "0", "]", "->", "invec", ",", "ej", "->", "rbfv", "[", "1", "]", "->", "invec", ")", ";", "return", "(", "cos_c", "-", "cos_aplusb", "<", ".001", ")", ";", "}" ]
Determine if we are close enough to an edge
[ "Determine", "if", "we", "are", "close", "enough", "to", "an", "edge" ]
[ "/* use triangle inequality */" ]
[ { "param": "ej", "type": "MIGRATION" }, { "param": "ivec", "type": "FVECT" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ej", "type": "MIGRATION", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "ivec", "type": "FVECT", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
ed7d897efc67da1dd490cceb8eb92d3a14144940
kalyanam-FMTGA/ray-original
src/cv/bsdfinterp.c
[ "BSD-3-Clause-LBNL" ]
C
in_tri
int
static int in_tri(const RBFNODE *v1, const RBFNODE *v2, const RBFNODE *v3, const FVECT p) { FVECT vc; int sgn1, sgn2, sgn3; /* signed volume test */ VCROSS(vc, v1->invec, v2->invec); sgn1 = (DOT(p, vc) > 0); VCROSS(vc, v2->invec, v3->invec); sgn2 = (DOT(p, vc) > 0); if (sgn1 != sgn2) return(0); VCROSS(vc, v3->invec, v1->invec); sgn3 = (DOT(p, vc) > 0); return(sgn2 == sgn3); }
/* Determine if we are inside the given triangle */
Determine if we are inside the given triangle
[ "Determine", "if", "we", "are", "inside", "the", "given", "triangle" ]
static int in_tri(const RBFNODE *v1, const RBFNODE *v2, const RBFNODE *v3, const FVECT p) { FVECT vc; int sgn1, sgn2, sgn3; VCROSS(vc, v1->invec, v2->invec); sgn1 = (DOT(p, vc) > 0); VCROSS(vc, v2->invec, v3->invec); sgn2 = (DOT(p, vc) > 0); if (sgn1 != sgn2) return(0); VCROSS(vc, v3->invec, v1->invec); sgn3 = (DOT(p, vc) > 0); return(sgn2 == sgn3); }
[ "static", "int", "in_tri", "(", "const", "RBFNODE", "*", "v1", ",", "const", "RBFNODE", "*", "v2", ",", "const", "RBFNODE", "*", "v3", ",", "const", "FVECT", "p", ")", "{", "FVECT", "vc", ";", "int", "sgn1", ",", "sgn2", ",", "sgn3", ";", "VCROSS", "(", "vc", ",", "v1", "->", "invec", ",", "v2", "->", "invec", ")", ";", "sgn1", "=", "(", "DOT", "(", "p", ",", "vc", ")", ">", "0", ")", ";", "VCROSS", "(", "vc", ",", "v2", "->", "invec", ",", "v3", "->", "invec", ")", ";", "sgn2", "=", "(", "DOT", "(", "p", ",", "vc", ")", ">", "0", ")", ";", "if", "(", "sgn1", "!=", "sgn2", ")", "return", "(", "0", ")", ";", "VCROSS", "(", "vc", ",", "v3", "->", "invec", ",", "v1", "->", "invec", ")", ";", "sgn3", "=", "(", "DOT", "(", "p", ",", "vc", ")", ">", "0", ")", ";", "return", "(", "sgn2", "==", "sgn3", ")", ";", "}" ]
Determine if we are inside the given triangle
[ "Determine", "if", "we", "are", "inside", "the", "given", "triangle" ]
[ "/* signed volume test */" ]
[ { "param": "v1", "type": "RBFNODE" }, { "param": "v2", "type": "RBFNODE" }, { "param": "v3", "type": "RBFNODE" }, { "param": "p", "type": "FVECT" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "v1", "type": "RBFNODE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "v2", "type": "RBFNODE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "v3", "type": "RBFNODE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "p", "type": "FVECT", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
ed7d897efc67da1dd490cceb8eb92d3a14144940
kalyanam-FMTGA/ray-original
src/cv/bsdfinterp.c
[ "BSD-3-Clause-LBNL" ]
C
check_edge
int
static int check_edge(unsigned char *emap, int nedges, const MIGRATION *mig, int mark) { int ejndx, bit2check; if (mig->rbfv[0]->ord > mig->rbfv[1]->ord) ejndx = mig->rbfv[1]->ord + (nedges-1)*mig->rbfv[0]->ord; else ejndx = mig->rbfv[0]->ord + (nedges-1)*mig->rbfv[1]->ord; bit2check = 1<<(ejndx&07); if (emap[ejndx>>3] & bit2check) return(0); if (mark) emap[ejndx>>3] |= bit2check; return(1); }
/* Test (and set) bitmap for edge */
Test (and set) bitmap for edge
[ "Test", "(", "and", "set", ")", "bitmap", "for", "edge" ]
static int check_edge(unsigned char *emap, int nedges, const MIGRATION *mig, int mark) { int ejndx, bit2check; if (mig->rbfv[0]->ord > mig->rbfv[1]->ord) ejndx = mig->rbfv[1]->ord + (nedges-1)*mig->rbfv[0]->ord; else ejndx = mig->rbfv[0]->ord + (nedges-1)*mig->rbfv[1]->ord; bit2check = 1<<(ejndx&07); if (emap[ejndx>>3] & bit2check) return(0); if (mark) emap[ejndx>>3] |= bit2check; return(1); }
[ "static", "int", "check_edge", "(", "unsigned", "char", "*", "emap", ",", "int", "nedges", ",", "const", "MIGRATION", "*", "mig", ",", "int", "mark", ")", "{", "int", "ejndx", ",", "bit2check", ";", "if", "(", "mig", "->", "rbfv", "[", "0", "]", "->", "ord", ">", "mig", "->", "rbfv", "[", "1", "]", "->", "ord", ")", "ejndx", "=", "mig", "->", "rbfv", "[", "1", "]", "->", "ord", "+", "(", "nedges", "-", "1", ")", "*", "mig", "->", "rbfv", "[", "0", "]", "->", "ord", ";", "else", "ejndx", "=", "mig", "->", "rbfv", "[", "0", "]", "->", "ord", "+", "(", "nedges", "-", "1", ")", "*", "mig", "->", "rbfv", "[", "1", "]", "->", "ord", ";", "bit2check", "=", "1", "<<", "(", "ejndx", "&", "07", ")", ";", "if", "(", "emap", "[", "ejndx", ">>", "3", "]", "&", "bit2check", ")", "return", "(", "0", ")", ";", "if", "(", "mark", ")", "emap", "[", "ejndx", ">>", "3", "]", "|=", "bit2check", ";", "return", "(", "1", ")", ";", "}" ]
Test (and set) bitmap for edge
[ "Test", "(", "and", "set", ")", "bitmap", "for", "edge" ]
[]
[ { "param": "emap", "type": "unsigned char" }, { "param": "nedges", "type": "int" }, { "param": "mig", "type": "MIGRATION" }, { "param": "mark", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "emap", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "nedges", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "mig", "type": "MIGRATION", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "mark", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
ed7d897efc67da1dd490cceb8eb92d3a14144940
kalyanam-FMTGA/ray-original
src/cv/bsdfinterp.c
[ "BSD-3-Clause-LBNL" ]
C
in_mesh
int
static int in_mesh(MIGRATION *miga[3], unsigned char *emap, int nedges, const FVECT ivec, MIGRATION *mig) { RBFNODE *tv[2]; MIGRATION *sej[2], *dej[2]; int i; /* check visitation record */ if (!check_edge(emap, nedges, mig, 1)) return(0); if (on_edge(mig, ivec)) { miga[0] = mig; /* close enough to edge */ return(1); } if (!get_triangles(tv, mig)) /* do triangles either side? */ return(0); for (i = 2; i--; ) { /* identify edges to check */ MIGRATION *ej; sej[i] = dej[i] = NULL; if (tv[i] == NULL) continue; for (ej = tv[i]->ejl; ej != NULL; ej = nextedge(tv[i],ej)) { RBFNODE *rbfop = opp_rbf(tv[i],ej); if (rbfop == mig->rbfv[0]) { if (check_edge(emap, nedges, ej, 0)) sej[i] = ej; } else if (rbfop == mig->rbfv[1]) { if (check_edge(emap, nedges, ej, 0)) dej[i] = ej; } } } for (i = 2; i--; ) { /* check triangles just once */ if (sej[i] != NULL && in_mesh(miga, emap, nedges, ivec, sej[i])) return(1); if (dej[i] != NULL && in_mesh(miga, emap, nedges, ivec, dej[i])) return(1); if ((sej[i] == NULL) | (dej[i] == NULL)) continue; if (in_tri(mig->rbfv[0], mig->rbfv[1], tv[i], ivec)) { miga[0] = mig; miga[1] = sej[i]; miga[2] = dej[i]; return(1); } } return(0); /* not near this edge */ }
/* Compute intersection with the given position over remaining mesh */
Compute intersection with the given position over remaining mesh
[ "Compute", "intersection", "with", "the", "given", "position", "over", "remaining", "mesh" ]
static int in_mesh(MIGRATION *miga[3], unsigned char *emap, int nedges, const FVECT ivec, MIGRATION *mig) { RBFNODE *tv[2]; MIGRATION *sej[2], *dej[2]; int i; if (!check_edge(emap, nedges, mig, 1)) return(0); if (on_edge(mig, ivec)) { miga[0] = mig; return(1); } if (!get_triangles(tv, mig)) return(0); for (i = 2; i--; ) { MIGRATION *ej; sej[i] = dej[i] = NULL; if (tv[i] == NULL) continue; for (ej = tv[i]->ejl; ej != NULL; ej = nextedge(tv[i],ej)) { RBFNODE *rbfop = opp_rbf(tv[i],ej); if (rbfop == mig->rbfv[0]) { if (check_edge(emap, nedges, ej, 0)) sej[i] = ej; } else if (rbfop == mig->rbfv[1]) { if (check_edge(emap, nedges, ej, 0)) dej[i] = ej; } } } for (i = 2; i--; ) { if (sej[i] != NULL && in_mesh(miga, emap, nedges, ivec, sej[i])) return(1); if (dej[i] != NULL && in_mesh(miga, emap, nedges, ivec, dej[i])) return(1); if ((sej[i] == NULL) | (dej[i] == NULL)) continue; if (in_tri(mig->rbfv[0], mig->rbfv[1], tv[i], ivec)) { miga[0] = mig; miga[1] = sej[i]; miga[2] = dej[i]; return(1); } } return(0); }
[ "static", "int", "in_mesh", "(", "MIGRATION", "*", "miga", "[", "3", "]", ",", "unsigned", "char", "*", "emap", ",", "int", "nedges", ",", "const", "FVECT", "ivec", ",", "MIGRATION", "*", "mig", ")", "{", "RBFNODE", "*", "tv", "[", "2", "]", ";", "MIGRATION", "*", "sej", "[", "2", "]", ",", "*", "dej", "[", "2", "]", ";", "int", "i", ";", "if", "(", "!", "check_edge", "(", "emap", ",", "nedges", ",", "mig", ",", "1", ")", ")", "return", "(", "0", ")", ";", "if", "(", "on_edge", "(", "mig", ",", "ivec", ")", ")", "{", "miga", "[", "0", "]", "=", "mig", ";", "return", "(", "1", ")", ";", "}", "if", "(", "!", "get_triangles", "(", "tv", ",", "mig", ")", ")", "return", "(", "0", ")", ";", "for", "(", "i", "=", "2", ";", "i", "--", ";", ")", "{", "MIGRATION", "*", "ej", ";", "sej", "[", "i", "]", "=", "dej", "[", "i", "]", "=", "NULL", ";", "if", "(", "tv", "[", "i", "]", "==", "NULL", ")", "continue", ";", "for", "(", "ej", "=", "tv", "[", "i", "]", "->", "ejl", ";", "ej", "!=", "NULL", ";", "ej", "=", "nextedge", "(", "tv", "[", "i", "]", ",", "ej", ")", ")", "{", "RBFNODE", "*", "rbfop", "=", "opp_rbf", "(", "tv", "[", "i", "]", ",", "ej", ")", ";", "if", "(", "rbfop", "==", "mig", "->", "rbfv", "[", "0", "]", ")", "{", "if", "(", "check_edge", "(", "emap", ",", "nedges", ",", "ej", ",", "0", ")", ")", "sej", "[", "i", "]", "=", "ej", ";", "}", "else", "if", "(", "rbfop", "==", "mig", "->", "rbfv", "[", "1", "]", ")", "{", "if", "(", "check_edge", "(", "emap", ",", "nedges", ",", "ej", ",", "0", ")", ")", "dej", "[", "i", "]", "=", "ej", ";", "}", "}", "}", "for", "(", "i", "=", "2", ";", "i", "--", ";", ")", "{", "if", "(", "sej", "[", "i", "]", "!=", "NULL", "&&", "in_mesh", "(", "miga", ",", "emap", ",", "nedges", ",", "ivec", ",", "sej", "[", "i", "]", ")", ")", "return", "(", "1", ")", ";", "if", "(", "dej", "[", "i", "]", "!=", "NULL", "&&", "in_mesh", "(", "miga", ",", "emap", ",", "nedges", ",", "ivec", ",", "dej", "[", "i", "]", ")", ")", "return", "(", "1", ")", ";", "if", "(", "(", "sej", "[", "i", "]", "==", "NULL", ")", "|", "(", "dej", "[", "i", "]", "==", "NULL", ")", ")", "continue", ";", "if", "(", "in_tri", "(", "mig", "->", "rbfv", "[", "0", "]", ",", "mig", "->", "rbfv", "[", "1", "]", ",", "tv", "[", "i", "]", ",", "ivec", ")", ")", "{", "miga", "[", "0", "]", "=", "mig", ";", "miga", "[", "1", "]", "=", "sej", "[", "i", "]", ";", "miga", "[", "2", "]", "=", "dej", "[", "i", "]", ";", "return", "(", "1", ")", ";", "}", "}", "return", "(", "0", ")", ";", "}" ]
Compute intersection with the given position over remaining mesh
[ "Compute", "intersection", "with", "the", "given", "position", "over", "remaining", "mesh" ]
[ "/* check visitation record */", "/* close enough to edge */", "/* do triangles either side? */", "/* identify edges to check */", "/* check triangles just once */", "/* not near this edge */" ]
[ { "param": "miga", "type": "MIGRATION" }, { "param": "emap", "type": "unsigned char" }, { "param": "nedges", "type": "int" }, { "param": "ivec", "type": "FVECT" }, { "param": "mig", "type": "MIGRATION" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "miga", "type": "MIGRATION", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "emap", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "nedges", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "ivec", "type": "FVECT", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "mig", "type": "MIGRATION", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
ed7d897efc67da1dd490cceb8eb92d3a14144940
kalyanam-FMTGA/ray-original
src/cv/bsdfinterp.c
[ "BSD-3-Clause-LBNL" ]
C
e_advect_rbf
RBFNODE
static RBFNODE * e_advect_rbf(const MIGRATION *mig, const FVECT invec) { RBFNODE *rbf; int n, i, j; double t, full_dist; /* get relative position */ t = acos(DOT(invec, mig->rbfv[0]->invec)); if (t < M_PI/grid_res) { /* near first DSF */ n = sizeof(RBFNODE) + sizeof(RBFVAL)*(mig->rbfv[0]->nrbf-1); rbf = (RBFNODE *)malloc(n); if (rbf == NULL) goto memerr; memcpy(rbf, mig->rbfv[0], n); /* just duplicate */ rbf->next = NULL; rbf->ejl = NULL; return(rbf); } full_dist = acos(DOT(mig->rbfv[0]->invec, mig->rbfv[1]->invec)); if (t > full_dist-M_PI/grid_res) { /* near second DSF */ n = sizeof(RBFNODE) + sizeof(RBFVAL)*(mig->rbfv[1]->nrbf-1); rbf = (RBFNODE *)malloc(n); if (rbf == NULL) goto memerr; memcpy(rbf, mig->rbfv[1], n); /* just duplicate */ rbf->next = NULL; rbf->ejl = NULL; return(rbf); } t /= full_dist; n = 0; /* count migrating particles */ for (i = 0; i < mtx_nrows(mig); i++) for (j = 0; j < mtx_ncols(mig); j++) n += (mtx_coef(mig,i,j) > FTINY); #ifdef DEBUG fprintf(stderr, "Input RBFs have %d, %d nodes -> output has %d\n", mig->rbfv[0]->nrbf, mig->rbfv[1]->nrbf, n); #endif rbf = (RBFNODE *)malloc(sizeof(RBFNODE) + sizeof(RBFVAL)*(n-1)); if (rbf == NULL) goto memerr; rbf->next = NULL; rbf->ejl = NULL; VCOPY(rbf->invec, invec); rbf->nrbf = n; rbf->vtotal = 1.-t + t*mig->rbfv[1]->vtotal/mig->rbfv[0]->vtotal; n = 0; /* advect RBF lobes */ for (i = 0; i < mtx_nrows(mig); i++) { const RBFVAL *rbf0i = &mig->rbfv[0]->rbfa[i]; const float peak0 = rbf0i->peak; const double rad0 = R2ANG(rbf0i->crad); FVECT v0; float mv; ovec_from_pos(v0, rbf0i->gx, rbf0i->gy); for (j = 0; j < mtx_ncols(mig); j++) if ((mv = mtx_coef(mig,i,j)) > FTINY) { const RBFVAL *rbf1j = &mig->rbfv[1]->rbfa[j]; double rad1 = R2ANG(rbf1j->crad); FVECT v; int pos[2]; rbf->rbfa[n].peak = peak0 * mv * rbf->vtotal; rbf->rbfa[n].crad = ANG2R(sqrt(rad0*rad0*(1.-t) + rad1*rad1*t)); ovec_from_pos(v, rbf1j->gx, rbf1j->gy); geodesic(v, v0, v, t, GEOD_REL); pos_from_vec(pos, v); rbf->rbfa[n].gx = pos[0]; rbf->rbfa[n].gy = pos[1]; ++n; } } rbf->vtotal *= mig->rbfv[0]->vtotal; /* turn ratio into actual */ return(rbf); memerr: fprintf(stderr, "%s: Out of memory in e_advect_rbf()\n", progname); exit(1); return(NULL); /* pro forma return */ }
/* Advect and allocate new RBF along edge */
Advect and allocate new RBF along edge
[ "Advect", "and", "allocate", "new", "RBF", "along", "edge" ]
static RBFNODE * e_advect_rbf(const MIGRATION *mig, const FVECT invec) { RBFNODE *rbf; int n, i, j; double t, full_dist; t = acos(DOT(invec, mig->rbfv[0]->invec)); if (t < M_PI/grid_res) { n = sizeof(RBFNODE) + sizeof(RBFVAL)*(mig->rbfv[0]->nrbf-1); rbf = (RBFNODE *)malloc(n); if (rbf == NULL) goto memerr; memcpy(rbf, mig->rbfv[0], n); rbf->next = NULL; rbf->ejl = NULL; return(rbf); } full_dist = acos(DOT(mig->rbfv[0]->invec, mig->rbfv[1]->invec)); if (t > full_dist-M_PI/grid_res) { n = sizeof(RBFNODE) + sizeof(RBFVAL)*(mig->rbfv[1]->nrbf-1); rbf = (RBFNODE *)malloc(n); if (rbf == NULL) goto memerr; memcpy(rbf, mig->rbfv[1], n); rbf->next = NULL; rbf->ejl = NULL; return(rbf); } t /= full_dist; n = 0; for (i = 0; i < mtx_nrows(mig); i++) for (j = 0; j < mtx_ncols(mig); j++) n += (mtx_coef(mig,i,j) > FTINY); #ifdef DEBUG fprintf(stderr, "Input RBFs have %d, %d nodes -> output has %d\n", mig->rbfv[0]->nrbf, mig->rbfv[1]->nrbf, n); #endif rbf = (RBFNODE *)malloc(sizeof(RBFNODE) + sizeof(RBFVAL)*(n-1)); if (rbf == NULL) goto memerr; rbf->next = NULL; rbf->ejl = NULL; VCOPY(rbf->invec, invec); rbf->nrbf = n; rbf->vtotal = 1.-t + t*mig->rbfv[1]->vtotal/mig->rbfv[0]->vtotal; n = 0; for (i = 0; i < mtx_nrows(mig); i++) { const RBFVAL *rbf0i = &mig->rbfv[0]->rbfa[i]; const float peak0 = rbf0i->peak; const double rad0 = R2ANG(rbf0i->crad); FVECT v0; float mv; ovec_from_pos(v0, rbf0i->gx, rbf0i->gy); for (j = 0; j < mtx_ncols(mig); j++) if ((mv = mtx_coef(mig,i,j)) > FTINY) { const RBFVAL *rbf1j = &mig->rbfv[1]->rbfa[j]; double rad1 = R2ANG(rbf1j->crad); FVECT v; int pos[2]; rbf->rbfa[n].peak = peak0 * mv * rbf->vtotal; rbf->rbfa[n].crad = ANG2R(sqrt(rad0*rad0*(1.-t) + rad1*rad1*t)); ovec_from_pos(v, rbf1j->gx, rbf1j->gy); geodesic(v, v0, v, t, GEOD_REL); pos_from_vec(pos, v); rbf->rbfa[n].gx = pos[0]; rbf->rbfa[n].gy = pos[1]; ++n; } } rbf->vtotal *= mig->rbfv[0]->vtotal; return(rbf); memerr: fprintf(stderr, "%s: Out of memory in e_advect_rbf()\n", progname); exit(1); return(NULL); }
[ "static", "RBFNODE", "*", "e_advect_rbf", "(", "const", "MIGRATION", "*", "mig", ",", "const", "FVECT", "invec", ")", "{", "RBFNODE", "*", "rbf", ";", "int", "n", ",", "i", ",", "j", ";", "double", "t", ",", "full_dist", ";", "t", "=", "acos", "(", "DOT", "(", "invec", ",", "mig", "->", "rbfv", "[", "0", "]", "->", "invec", ")", ")", ";", "if", "(", "t", "<", "M_PI", "/", "grid_res", ")", "{", "n", "=", "sizeof", "(", "RBFNODE", ")", "+", "sizeof", "(", "RBFVAL", ")", "*", "(", "mig", "->", "rbfv", "[", "0", "]", "->", "nrbf", "-", "1", ")", ";", "rbf", "=", "(", "RBFNODE", "*", ")", "malloc", "(", "n", ")", ";", "if", "(", "rbf", "==", "NULL", ")", "goto", "memerr", ";", "memcpy", "(", "rbf", ",", "mig", "->", "rbfv", "[", "0", "]", ",", "n", ")", ";", "rbf", "->", "next", "=", "NULL", ";", "rbf", "->", "ejl", "=", "NULL", ";", "return", "(", "rbf", ")", ";", "}", "full_dist", "=", "acos", "(", "DOT", "(", "mig", "->", "rbfv", "[", "0", "]", "->", "invec", ",", "mig", "->", "rbfv", "[", "1", "]", "->", "invec", ")", ")", ";", "if", "(", "t", ">", "full_dist", "-", "M_PI", "/", "grid_res", ")", "{", "n", "=", "sizeof", "(", "RBFNODE", ")", "+", "sizeof", "(", "RBFVAL", ")", "*", "(", "mig", "->", "rbfv", "[", "1", "]", "->", "nrbf", "-", "1", ")", ";", "rbf", "=", "(", "RBFNODE", "*", ")", "malloc", "(", "n", ")", ";", "if", "(", "rbf", "==", "NULL", ")", "goto", "memerr", ";", "memcpy", "(", "rbf", ",", "mig", "->", "rbfv", "[", "1", "]", ",", "n", ")", ";", "rbf", "->", "next", "=", "NULL", ";", "rbf", "->", "ejl", "=", "NULL", ";", "return", "(", "rbf", ")", ";", "}", "t", "/=", "full_dist", ";", "n", "=", "0", ";", "for", "(", "i", "=", "0", ";", "i", "<", "mtx_nrows", "(", "mig", ")", ";", "i", "++", ")", "for", "(", "j", "=", "0", ";", "j", "<", "mtx_ncols", "(", "mig", ")", ";", "j", "++", ")", "n", "+=", "(", "mtx_coef", "(", "mig", ",", "i", ",", "j", ")", ">", "FTINY", ")", ";", "#ifdef", "DEBUG", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "mig", "->", "rbfv", "[", "0", "]", "->", "nrbf", ",", "mig", "->", "rbfv", "[", "1", "]", "->", "nrbf", ",", "n", ")", ";", "#endif", "rbf", "=", "(", "RBFNODE", "*", ")", "malloc", "(", "sizeof", "(", "RBFNODE", ")", "+", "sizeof", "(", "RBFVAL", ")", "*", "(", "n", "-", "1", ")", ")", ";", "if", "(", "rbf", "==", "NULL", ")", "goto", "memerr", ";", "rbf", "->", "next", "=", "NULL", ";", "rbf", "->", "ejl", "=", "NULL", ";", "VCOPY", "(", "rbf", "->", "invec", ",", "invec", ")", ";", "rbf", "->", "nrbf", "=", "n", ";", "rbf", "->", "vtotal", "=", "1.", "-", "t", "+", "t", "*", "mig", "->", "rbfv", "[", "1", "]", "->", "vtotal", "/", "mig", "->", "rbfv", "[", "0", "]", "->", "vtotal", ";", "n", "=", "0", ";", "for", "(", "i", "=", "0", ";", "i", "<", "mtx_nrows", "(", "mig", ")", ";", "i", "++", ")", "{", "const", "RBFVAL", "*", "rbf0i", "=", "&", "mig", "->", "rbfv", "[", "0", "]", "->", "rbfa", "[", "i", "]", ";", "const", "float", "peak0", "=", "rbf0i", "->", "peak", ";", "const", "double", "rad0", "=", "R2ANG", "(", "rbf0i", "->", "crad", ")", ";", "FVECT", "v0", ";", "float", "mv", ";", "ovec_from_pos", "(", "v0", ",", "rbf0i", "->", "gx", ",", "rbf0i", "->", "gy", ")", ";", "for", "(", "j", "=", "0", ";", "j", "<", "mtx_ncols", "(", "mig", ")", ";", "j", "++", ")", "if", "(", "(", "mv", "=", "mtx_coef", "(", "mig", ",", "i", ",", "j", ")", ")", ">", "FTINY", ")", "{", "const", "RBFVAL", "*", "rbf1j", "=", "&", "mig", "->", "rbfv", "[", "1", "]", "->", "rbfa", "[", "j", "]", ";", "double", "rad1", "=", "R2ANG", "(", "rbf1j", "->", "crad", ")", ";", "FVECT", "v", ";", "int", "pos", "[", "2", "]", ";", "rbf", "->", "rbfa", "[", "n", "]", ".", "peak", "=", "peak0", "*", "mv", "*", "rbf", "->", "vtotal", ";", "rbf", "->", "rbfa", "[", "n", "]", ".", "crad", "=", "ANG2R", "(", "sqrt", "(", "rad0", "*", "rad0", "*", "(", "1.", "-", "t", ")", "+", "rad1", "*", "rad1", "*", "t", ")", ")", ";", "ovec_from_pos", "(", "v", ",", "rbf1j", "->", "gx", ",", "rbf1j", "->", "gy", ")", ";", "geodesic", "(", "v", ",", "v0", ",", "v", ",", "t", ",", "GEOD_REL", ")", ";", "pos_from_vec", "(", "pos", ",", "v", ")", ";", "rbf", "->", "rbfa", "[", "n", "]", ".", "gx", "=", "pos", "[", "0", "]", ";", "rbf", "->", "rbfa", "[", "n", "]", ".", "gy", "=", "pos", "[", "1", "]", ";", "++", "n", ";", "}", "}", "rbf", "->", "vtotal", "*=", "mig", "->", "rbfv", "[", "0", "]", "->", "vtotal", ";", "return", "(", "rbf", ")", ";", "memerr", ":", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "progname", ")", ";", "exit", "(", "1", ")", ";", "return", "(", "NULL", ")", ";", "}" ]
Advect and allocate new RBF along edge
[ "Advect", "and", "allocate", "new", "RBF", "along", "edge" ]
[ "/* get relative position */", "/* near first DSF */", "/* just duplicate */", "/* near second DSF */", "/* just duplicate */", "/* count migrating particles */", "/* advect RBF lobes */", "/* turn ratio into actual */", "/* pro forma return */" ]
[ { "param": "mig", "type": "MIGRATION" }, { "param": "invec", "type": "FVECT" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "mig", "type": "MIGRATION", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "invec", "type": "FVECT", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
f8f0901ddf14727a3fa12120e13dd701f9776e24
kalyanam-FMTGA/ray-original
src/px/pmapgen.c
[ "BSD-3-Clause-LBNL" ]
C
pmap_quad_rect
int
extern int pmap_quad_rect( double u0, /* bounds of rectangle */ double v0, double u1, double v1, double qdrl[4][2], /* vertices of quadrilateral */ double QR[3][3] /* qdrl->rect transform (returned) */ ) { int ret; double du, dv; double RQ[3][3]; /* rect->qdrl transform */ du = u1-u0; dv = v1-v0; if (du==0. || dv==0.) { fprintf(stderr, "pmap_quad_rect: null rectangle\n"); return PMAP_BAD; } /* first find mapping from unit uv square to xy quadrilateral */ ret = pmap_square_quad(qdrl, RQ); if (ret==PMAP_BAD) return PMAP_BAD; /* concatenate transform from uv rectangle (u0,v0,u1,v1) to unit square */ RQ[0][0] /= du; RQ[1][0] /= dv; RQ[2][0] -= RQ[0][0]*u0 + RQ[1][0]*v0; RQ[0][1] /= du; RQ[1][1] /= dv; RQ[2][1] -= RQ[0][1]*u0 + RQ[1][1]*v0; RQ[0][2] /= du; RQ[1][2] /= dv; RQ[2][2] -= RQ[0][2]*u0 + RQ[1][2]*v0; /* now RQ is transform from uv rectangle to xy quadrilateral */ /* QR = inverse transform, which maps xy to uv */ if (mx3d_adjoint(RQ, QR)==0.) fprintf(stderr, "pmap_quad_rect: warning: determinant=0\n"); return ret; }
/* * pmap_quad_rect: find mapping between quadrilateral and rectangle. * The correspondence is: * * qdrl[0] --> (u0,v0) * qdrl[1] --> (u1,v0) * qdrl[2] --> (u1,v1) * qdrl[3] --> (u0,v1) * * This method of computing the adjoint numerically is cheaper than * computing it symbolically. */
find mapping between quadrilateral and rectangle. The correspondence is. This method of computing the adjoint numerically is cheaper than computing it symbolically.
[ "find", "mapping", "between", "quadrilateral", "and", "rectangle", ".", "The", "correspondence", "is", ".", "This", "method", "of", "computing", "the", "adjoint", "numerically", "is", "cheaper", "than", "computing", "it", "symbolically", "." ]
extern int pmap_quad_rect( double u0, double v0, double u1, double v1, double qdrl[4][2], double QR[3][3] ) { int ret; double du, dv; double RQ[3][3]; du = u1-u0; dv = v1-v0; if (du==0. || dv==0.) { fprintf(stderr, "pmap_quad_rect: null rectangle\n"); return PMAP_BAD; } ret = pmap_square_quad(qdrl, RQ); if (ret==PMAP_BAD) return PMAP_BAD; RQ[0][0] /= du; RQ[1][0] /= dv; RQ[2][0] -= RQ[0][0]*u0 + RQ[1][0]*v0; RQ[0][1] /= du; RQ[1][1] /= dv; RQ[2][1] -= RQ[0][1]*u0 + RQ[1][1]*v0; RQ[0][2] /= du; RQ[1][2] /= dv; RQ[2][2] -= RQ[0][2]*u0 + RQ[1][2]*v0; if (mx3d_adjoint(RQ, QR)==0.) fprintf(stderr, "pmap_quad_rect: warning: determinant=0\n"); return ret; }
[ "extern", "int", "pmap_quad_rect", "(", "double", "u0", ",", "double", "v0", ",", "double", "u1", ",", "double", "v1", ",", "double", "qdrl", "[", "4", "]", "[", "2", "]", ",", "double", "QR", "[", "3", "]", "[", "3", "]", ")", "{", "int", "ret", ";", "double", "du", ",", "dv", ";", "double", "RQ", "[", "3", "]", "[", "3", "]", ";", "du", "=", "u1", "-", "u0", ";", "dv", "=", "v1", "-", "v0", ";", "if", "(", "du", "==", "0.", "||", "dv", "==", "0.", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ")", ";", "return", "PMAP_BAD", ";", "}", "ret", "=", "pmap_square_quad", "(", "qdrl", ",", "RQ", ")", ";", "if", "(", "ret", "==", "PMAP_BAD", ")", "return", "PMAP_BAD", ";", "RQ", "[", "0", "]", "[", "0", "]", "/=", "du", ";", "RQ", "[", "1", "]", "[", "0", "]", "/=", "dv", ";", "RQ", "[", "2", "]", "[", "0", "]", "-=", "RQ", "[", "0", "]", "[", "0", "]", "*", "u0", "+", "RQ", "[", "1", "]", "[", "0", "]", "*", "v0", ";", "RQ", "[", "0", "]", "[", "1", "]", "/=", "du", ";", "RQ", "[", "1", "]", "[", "1", "]", "/=", "dv", ";", "RQ", "[", "2", "]", "[", "1", "]", "-=", "RQ", "[", "0", "]", "[", "1", "]", "*", "u0", "+", "RQ", "[", "1", "]", "[", "1", "]", "*", "v0", ";", "RQ", "[", "0", "]", "[", "2", "]", "/=", "du", ";", "RQ", "[", "1", "]", "[", "2", "]", "/=", "dv", ";", "RQ", "[", "2", "]", "[", "2", "]", "-=", "RQ", "[", "0", "]", "[", "2", "]", "*", "u0", "+", "RQ", "[", "1", "]", "[", "2", "]", "*", "v0", ";", "if", "(", "mx3d_adjoint", "(", "RQ", ",", "QR", ")", "==", "0.", ")", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ")", ";", "return", "ret", ";", "}" ]
pmap_quad_rect: find mapping between quadrilateral and rectangle.
[ "pmap_quad_rect", ":", "find", "mapping", "between", "quadrilateral", "and", "rectangle", "." ]
[ "/* bounds of rectangle */", "/* vertices of quadrilateral */", "/* qdrl->rect transform (returned) */", "/* rect->qdrl transform */", "/* first find mapping from unit uv square to xy quadrilateral */", "/* concatenate transform from uv rectangle (u0,v0,u1,v1) to unit square */", "/* now RQ is transform from uv rectangle to xy quadrilateral */", "/* QR = inverse transform, which maps xy to uv */" ]
[ { "param": "u0", "type": "double" }, { "param": "v0", "type": "double" }, { "param": "u1", "type": "double" }, { "param": "v1", "type": "double" }, { "param": "qdrl", "type": "double" }, { "param": "QR", "type": "double" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "u0", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "v0", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "u1", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "v1", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "qdrl", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "QR", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
f8f0901ddf14727a3fa12120e13dd701f9776e24
kalyanam-FMTGA/ray-original
src/px/pmapgen.c
[ "BSD-3-Clause-LBNL" ]
C
pmap_square_quad
int
extern int pmap_square_quad( register double qdrl[4][2], /* vertices of quadrilateral */ register double SQ[3][3] /* square->qdrl transform */ ) { double px, py; px = X(0)-X(1)+X(2)-X(3); py = Y(0)-Y(1)+Y(2)-Y(3); if (ZERO(px) && ZERO(py)) { /* affine */ SQ[0][0] = X(1)-X(0); SQ[1][0] = X(2)-X(1); SQ[2][0] = X(0); SQ[0][1] = Y(1)-Y(0); SQ[1][1] = Y(2)-Y(1); SQ[2][1] = Y(0); SQ[0][2] = 0.; SQ[1][2] = 0.; SQ[2][2] = 1.; return PMAP_LINEAR; } else { /* perspective */ double dx1, dx2, dy1, dy2, del; dx1 = X(1)-X(2); dx2 = X(3)-X(2); dy1 = Y(1)-Y(2); dy2 = Y(3)-Y(2); del = DET2(dx1,dx2, dy1,dy2); if (del==0.) { fprintf(stderr, "pmap_square_quad: bad mapping\n"); return PMAP_BAD; } SQ[0][2] = DET2(px,dx2, py,dy2)/del; SQ[1][2] = DET2(dx1,px, dy1,py)/del; SQ[2][2] = 1.; SQ[0][0] = X(1)-X(0)+SQ[0][2]*X(1); SQ[1][0] = X(3)-X(0)+SQ[1][2]*X(3); SQ[2][0] = X(0); SQ[0][1] = Y(1)-Y(0)+SQ[0][2]*Y(1); SQ[1][1] = Y(3)-Y(0)+SQ[1][2]*Y(3); SQ[2][1] = Y(0); return PMAP_PERSP; } }
/* * pmap_square_quad: find mapping between unit square and quadrilateral. * The correspondence is: * * (0,0) --> qdrl[0] * (1,0) --> qdrl[1] * (1,1) --> qdrl[2] * (0,1) --> qdrl[3] */
find mapping between unit square and quadrilateral. The correspondence is.
[ "find", "mapping", "between", "unit", "square", "and", "quadrilateral", ".", "The", "correspondence", "is", "." ]
extern int pmap_square_quad( register double qdrl[4][2], register double SQ[3][3] ) { double px, py; px = X(0)-X(1)+X(2)-X(3); py = Y(0)-Y(1)+Y(2)-Y(3); if (ZERO(px) && ZERO(py)) { SQ[0][0] = X(1)-X(0); SQ[1][0] = X(2)-X(1); SQ[2][0] = X(0); SQ[0][1] = Y(1)-Y(0); SQ[1][1] = Y(2)-Y(1); SQ[2][1] = Y(0); SQ[0][2] = 0.; SQ[1][2] = 0.; SQ[2][2] = 1.; return PMAP_LINEAR; } else { double dx1, dx2, dy1, dy2, del; dx1 = X(1)-X(2); dx2 = X(3)-X(2); dy1 = Y(1)-Y(2); dy2 = Y(3)-Y(2); del = DET2(dx1,dx2, dy1,dy2); if (del==0.) { fprintf(stderr, "pmap_square_quad: bad mapping\n"); return PMAP_BAD; } SQ[0][2] = DET2(px,dx2, py,dy2)/del; SQ[1][2] = DET2(dx1,px, dy1,py)/del; SQ[2][2] = 1.; SQ[0][0] = X(1)-X(0)+SQ[0][2]*X(1); SQ[1][0] = X(3)-X(0)+SQ[1][2]*X(3); SQ[2][0] = X(0); SQ[0][1] = Y(1)-Y(0)+SQ[0][2]*Y(1); SQ[1][1] = Y(3)-Y(0)+SQ[1][2]*Y(3); SQ[2][1] = Y(0); return PMAP_PERSP; } }
[ "extern", "int", "pmap_square_quad", "(", "register", "double", "qdrl", "[", "4", "]", "[", "2", "]", ",", "register", "double", "SQ", "[", "3", "]", "[", "3", "]", ")", "{", "double", "px", ",", "py", ";", "px", "=", "X", "(", "0", ")", "-", "X", "(", "1", ")", "+", "X", "(", "2", ")", "-", "X", "(", "3", ")", ";", "py", "=", "Y", "(", "0", ")", "-", "Y", "(", "1", ")", "+", "Y", "(", "2", ")", "-", "Y", "(", "3", ")", ";", "if", "(", "ZERO", "(", "px", ")", "&&", "ZERO", "(", "py", ")", ")", "{", "SQ", "[", "0", "]", "[", "0", "]", "=", "X", "(", "1", ")", "-", "X", "(", "0", ")", ";", "SQ", "[", "1", "]", "[", "0", "]", "=", "X", "(", "2", ")", "-", "X", "(", "1", ")", ";", "SQ", "[", "2", "]", "[", "0", "]", "=", "X", "(", "0", ")", ";", "SQ", "[", "0", "]", "[", "1", "]", "=", "Y", "(", "1", ")", "-", "Y", "(", "0", ")", ";", "SQ", "[", "1", "]", "[", "1", "]", "=", "Y", "(", "2", ")", "-", "Y", "(", "1", ")", ";", "SQ", "[", "2", "]", "[", "1", "]", "=", "Y", "(", "0", ")", ";", "SQ", "[", "0", "]", "[", "2", "]", "=", "0.", ";", "SQ", "[", "1", "]", "[", "2", "]", "=", "0.", ";", "SQ", "[", "2", "]", "[", "2", "]", "=", "1.", ";", "return", "PMAP_LINEAR", ";", "}", "else", "{", "double", "dx1", ",", "dx2", ",", "dy1", ",", "dy2", ",", "del", ";", "dx1", "=", "X", "(", "1", ")", "-", "X", "(", "2", ")", ";", "dx2", "=", "X", "(", "3", ")", "-", "X", "(", "2", ")", ";", "dy1", "=", "Y", "(", "1", ")", "-", "Y", "(", "2", ")", ";", "dy2", "=", "Y", "(", "3", ")", "-", "Y", "(", "2", ")", ";", "del", "=", "DET2", "(", "dx1", ",", "dx2", ",", "dy1", ",", "dy2", ")", ";", "if", "(", "del", "==", "0.", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ")", ";", "return", "PMAP_BAD", ";", "}", "SQ", "[", "0", "]", "[", "2", "]", "=", "DET2", "(", "px", ",", "dx2", ",", "py", ",", "dy2", ")", "/", "del", ";", "SQ", "[", "1", "]", "[", "2", "]", "=", "DET2", "(", "dx1", ",", "px", ",", "dy1", ",", "py", ")", "/", "del", ";", "SQ", "[", "2", "]", "[", "2", "]", "=", "1.", ";", "SQ", "[", "0", "]", "[", "0", "]", "=", "X", "(", "1", ")", "-", "X", "(", "0", ")", "+", "SQ", "[", "0", "]", "[", "2", "]", "*", "X", "(", "1", ")", ";", "SQ", "[", "1", "]", "[", "0", "]", "=", "X", "(", "3", ")", "-", "X", "(", "0", ")", "+", "SQ", "[", "1", "]", "[", "2", "]", "*", "X", "(", "3", ")", ";", "SQ", "[", "2", "]", "[", "0", "]", "=", "X", "(", "0", ")", ";", "SQ", "[", "0", "]", "[", "1", "]", "=", "Y", "(", "1", ")", "-", "Y", "(", "0", ")", "+", "SQ", "[", "0", "]", "[", "2", "]", "*", "Y", "(", "1", ")", ";", "SQ", "[", "1", "]", "[", "1", "]", "=", "Y", "(", "3", ")", "-", "Y", "(", "0", ")", "+", "SQ", "[", "1", "]", "[", "2", "]", "*", "Y", "(", "3", ")", ";", "SQ", "[", "2", "]", "[", "1", "]", "=", "Y", "(", "0", ")", ";", "return", "PMAP_PERSP", ";", "}", "}" ]
pmap_square_quad: find mapping between unit square and quadrilateral.
[ "pmap_square_quad", ":", "find", "mapping", "between", "unit", "square", "and", "quadrilateral", "." ]
[ "/* vertices of quadrilateral */", "/* square->qdrl transform */", "/* affine */", "/* perspective */" ]
[ { "param": "qdrl", "type": "double" }, { "param": "SQ", "type": "double" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "qdrl", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "SQ", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
404a3ab1808618bc18d75ef3f96ae6eaf67b2f25
kalyanam-FMTGA/ray-original
src/cv/vect3ds.c
[ "BSD-3-Clause-LBNL" ]
C
vect_angle
float
float vect_angle (Vector v1, Vector v2) { float mag1, mag2, angle, cos_theta; mag1 = vect_mag(v1); mag2 = vect_mag(v2); if (mag1 * mag2 == 0.0) angle = 0.0; else { cos_theta = vect_dot(v1,v2) / (mag1 * mag2); if (cos_theta <= -1.0) angle = 180.0; else if (cos_theta >= +1.0) angle = 0.0; else angle = (180.0/PI) * acos(cos_theta); } return angle; }
/* Return the angle between two vectors */
Return the angle between two vectors
[ "Return", "the", "angle", "between", "two", "vectors" ]
float vect_angle (Vector v1, Vector v2) { float mag1, mag2, angle, cos_theta; mag1 = vect_mag(v1); mag2 = vect_mag(v2); if (mag1 * mag2 == 0.0) angle = 0.0; else { cos_theta = vect_dot(v1,v2) / (mag1 * mag2); if (cos_theta <= -1.0) angle = 180.0; else if (cos_theta >= +1.0) angle = 0.0; else angle = (180.0/PI) * acos(cos_theta); } return angle; }
[ "float", "vect_angle", "(", "Vector", "v1", ",", "Vector", "v2", ")", "{", "float", "mag1", ",", "mag2", ",", "angle", ",", "cos_theta", ";", "mag1", "=", "vect_mag", "(", "v1", ")", ";", "mag2", "=", "vect_mag", "(", "v2", ")", ";", "if", "(", "mag1", "*", "mag2", "==", "0.0", ")", "angle", "=", "0.0", ";", "else", "{", "cos_theta", "=", "vect_dot", "(", "v1", ",", "v2", ")", "/", "(", "mag1", "*", "mag2", ")", ";", "if", "(", "cos_theta", "<=", "-1.0", ")", "angle", "=", "180.0", ";", "else", "if", "(", "cos_theta", ">=", "+1.0", ")", "angle", "=", "0.0", ";", "else", "angle", "=", "(", "180.0", "/", "PI", ")", "*", "acos", "(", "cos_theta", ")", ";", "}", "return", "angle", ";", "}" ]
Return the angle between two vectors
[ "Return", "the", "angle", "between", "two", "vectors" ]
[]
[ { "param": "v1", "type": "Vector" }, { "param": "v2", "type": "Vector" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "v1", "type": "Vector", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "v2", "type": "Vector", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
404a3ab1808618bc18d75ef3f96ae6eaf67b2f25
kalyanam-FMTGA/ray-original
src/cv/vect3ds.c
[ "BSD-3-Clause-LBNL" ]
C
vect_rotate
void
void vect_rotate (Vector v1, Vector v2, int axis, float angle) { float cosa, sina; cosa = cos ((PI/180.0) * angle); sina = sin ((PI/180.0) * angle); switch (axis) { case X: v1[X] = v2[X]; v1[Y] = v2[Y] * cosa + v2[Z] * sina; v1[Z] = v2[Z] * cosa - v2[Y] * sina; break; case Y: v1[X] = v2[X] * cosa - v2[Z] * sina; v1[Y] = v2[Y]; v1[Z] = v2[Z] * cosa + v2[X] * sina; break; case Z: v1[X] = v2[X] * cosa + v2[Y] * sina; v1[Y] = v2[Y] * cosa - v2[X] * sina; v1[Z] = v2[Z]; break; } }
/* Rotate a vector about the X, Y or Z axis */
Rotate a vector about the X, Y or Z axis
[ "Rotate", "a", "vector", "about", "the", "X", "Y", "or", "Z", "axis" ]
void vect_rotate (Vector v1, Vector v2, int axis, float angle) { float cosa, sina; cosa = cos ((PI/180.0) * angle); sina = sin ((PI/180.0) * angle); switch (axis) { case X: v1[X] = v2[X]; v1[Y] = v2[Y] * cosa + v2[Z] * sina; v1[Z] = v2[Z] * cosa - v2[Y] * sina; break; case Y: v1[X] = v2[X] * cosa - v2[Z] * sina; v1[Y] = v2[Y]; v1[Z] = v2[Z] * cosa + v2[X] * sina; break; case Z: v1[X] = v2[X] * cosa + v2[Y] * sina; v1[Y] = v2[Y] * cosa - v2[X] * sina; v1[Z] = v2[Z]; break; } }
[ "void", "vect_rotate", "(", "Vector", "v1", ",", "Vector", "v2", ",", "int", "axis", ",", "float", "angle", ")", "{", "float", "cosa", ",", "sina", ";", "cosa", "=", "cos", "(", "(", "PI", "/", "180.0", ")", "*", "angle", ")", ";", "sina", "=", "sin", "(", "(", "PI", "/", "180.0", ")", "*", "angle", ")", ";", "switch", "(", "axis", ")", "{", "case", "X", ":", "v1", "[", "X", "]", "=", "v2", "[", "X", "]", ";", "v1", "[", "Y", "]", "=", "v2", "[", "Y", "]", "*", "cosa", "+", "v2", "[", "Z", "]", "*", "sina", ";", "v1", "[", "Z", "]", "=", "v2", "[", "Z", "]", "*", "cosa", "-", "v2", "[", "Y", "]", "*", "sina", ";", "break", ";", "case", "Y", ":", "v1", "[", "X", "]", "=", "v2", "[", "X", "]", "*", "cosa", "-", "v2", "[", "Z", "]", "*", "sina", ";", "v1", "[", "Y", "]", "=", "v2", "[", "Y", "]", ";", "v1", "[", "Z", "]", "=", "v2", "[", "Z", "]", "*", "cosa", "+", "v2", "[", "X", "]", "*", "sina", ";", "break", ";", "case", "Z", ":", "v1", "[", "X", "]", "=", "v2", "[", "X", "]", "*", "cosa", "+", "v2", "[", "Y", "]", "*", "sina", ";", "v1", "[", "Y", "]", "=", "v2", "[", "Y", "]", "*", "cosa", "-", "v2", "[", "X", "]", "*", "sina", ";", "v1", "[", "Z", "]", "=", "v2", "[", "Z", "]", ";", "break", ";", "}", "}" ]
Rotate a vector about the X, Y or Z axis
[ "Rotate", "a", "vector", "about", "the", "X", "Y", "or", "Z", "axis" ]
[]
[ { "param": "v1", "type": "Vector" }, { "param": "v2", "type": "Vector" }, { "param": "axis", "type": "int" }, { "param": "angle", "type": "float" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "v1", "type": "Vector", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "v2", "type": "Vector", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "axis", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "angle", "type": "float", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
404a3ab1808618bc18d75ef3f96ae6eaf67b2f25
kalyanam-FMTGA/ray-original
src/cv/vect3ds.c
[ "BSD-3-Clause-LBNL" ]
C
vect_axis_rotate
void
void vect_axis_rotate (Vector v1, Vector v2, Vector axis, float angle) { float cosa, sina; Matrix mat; cosa = cos ((PI/180.0) * angle); sina = sin ((PI/180.0) * angle); mat[0][0] = (axis[X] * axis[X]) + ((1.0 - (axis[X] * axis[X]))*cosa); mat[0][1] = (axis[X] * axis[Y] * (1.0 - cosa)) - (axis[Z] * sina); mat[0][2] = (axis[X] * axis[Z] * (1.0 - cosa)) + (axis[Y] * sina); mat[0][3] = 0.0; mat[1][0] = (axis[X] * axis[Y] * (1.0 - cosa)) + (axis[Z] * sina); mat[1][1] = (axis[Y] * axis[Y]) + ((1.0 - (axis[Y] * axis[Y])) * cosa); mat[1][2] = (axis[Y] * axis[Z] * (1.0 - cosa)) - (axis[X] * sina); mat[1][3] = 0.0; mat[2][0] = (axis[X] * axis[Z] * (1.0 - cosa)) - (axis[Y] * sina); mat[2][1] = (axis[Y] * axis[Z] * (1.0 - cosa)) + (axis[X] * sina); mat[2][2] = (axis[Z] * axis[Z]) + ((1.0 - (axis[Z] * axis[Z])) * cosa); mat[2][3] = 0.0; mat[3][0] = mat[3][1] = mat[3][2] = mat[3][3] = 0.0; vect_transform (v1, v2, mat); }
/* Rotate a vector about a specific axis */
Rotate a vector about a specific axis
[ "Rotate", "a", "vector", "about", "a", "specific", "axis" ]
void vect_axis_rotate (Vector v1, Vector v2, Vector axis, float angle) { float cosa, sina; Matrix mat; cosa = cos ((PI/180.0) * angle); sina = sin ((PI/180.0) * angle); mat[0][0] = (axis[X] * axis[X]) + ((1.0 - (axis[X] * axis[X]))*cosa); mat[0][1] = (axis[X] * axis[Y] * (1.0 - cosa)) - (axis[Z] * sina); mat[0][2] = (axis[X] * axis[Z] * (1.0 - cosa)) + (axis[Y] * sina); mat[0][3] = 0.0; mat[1][0] = (axis[X] * axis[Y] * (1.0 - cosa)) + (axis[Z] * sina); mat[1][1] = (axis[Y] * axis[Y]) + ((1.0 - (axis[Y] * axis[Y])) * cosa); mat[1][2] = (axis[Y] * axis[Z] * (1.0 - cosa)) - (axis[X] * sina); mat[1][3] = 0.0; mat[2][0] = (axis[X] * axis[Z] * (1.0 - cosa)) - (axis[Y] * sina); mat[2][1] = (axis[Y] * axis[Z] * (1.0 - cosa)) + (axis[X] * sina); mat[2][2] = (axis[Z] * axis[Z]) + ((1.0 - (axis[Z] * axis[Z])) * cosa); mat[2][3] = 0.0; mat[3][0] = mat[3][1] = mat[3][2] = mat[3][3] = 0.0; vect_transform (v1, v2, mat); }
[ "void", "vect_axis_rotate", "(", "Vector", "v1", ",", "Vector", "v2", ",", "Vector", "axis", ",", "float", "angle", ")", "{", "float", "cosa", ",", "sina", ";", "Matrix", "mat", ";", "cosa", "=", "cos", "(", "(", "PI", "/", "180.0", ")", "*", "angle", ")", ";", "sina", "=", "sin", "(", "(", "PI", "/", "180.0", ")", "*", "angle", ")", ";", "mat", "[", "0", "]", "[", "0", "]", "=", "(", "axis", "[", "X", "]", "*", "axis", "[", "X", "]", ")", "+", "(", "(", "1.0", "-", "(", "axis", "[", "X", "]", "*", "axis", "[", "X", "]", ")", ")", "*", "cosa", ")", ";", "mat", "[", "0", "]", "[", "1", "]", "=", "(", "axis", "[", "X", "]", "*", "axis", "[", "Y", "]", "*", "(", "1.0", "-", "cosa", ")", ")", "-", "(", "axis", "[", "Z", "]", "*", "sina", ")", ";", "mat", "[", "0", "]", "[", "2", "]", "=", "(", "axis", "[", "X", "]", "*", "axis", "[", "Z", "]", "*", "(", "1.0", "-", "cosa", ")", ")", "+", "(", "axis", "[", "Y", "]", "*", "sina", ")", ";", "mat", "[", "0", "]", "[", "3", "]", "=", "0.0", ";", "mat", "[", "1", "]", "[", "0", "]", "=", "(", "axis", "[", "X", "]", "*", "axis", "[", "Y", "]", "*", "(", "1.0", "-", "cosa", ")", ")", "+", "(", "axis", "[", "Z", "]", "*", "sina", ")", ";", "mat", "[", "1", "]", "[", "1", "]", "=", "(", "axis", "[", "Y", "]", "*", "axis", "[", "Y", "]", ")", "+", "(", "(", "1.0", "-", "(", "axis", "[", "Y", "]", "*", "axis", "[", "Y", "]", ")", ")", "*", "cosa", ")", ";", "mat", "[", "1", "]", "[", "2", "]", "=", "(", "axis", "[", "Y", "]", "*", "axis", "[", "Z", "]", "*", "(", "1.0", "-", "cosa", ")", ")", "-", "(", "axis", "[", "X", "]", "*", "sina", ")", ";", "mat", "[", "1", "]", "[", "3", "]", "=", "0.0", ";", "mat", "[", "2", "]", "[", "0", "]", "=", "(", "axis", "[", "X", "]", "*", "axis", "[", "Z", "]", "*", "(", "1.0", "-", "cosa", ")", ")", "-", "(", "axis", "[", "Y", "]", "*", "sina", ")", ";", "mat", "[", "2", "]", "[", "1", "]", "=", "(", "axis", "[", "Y", "]", "*", "axis", "[", "Z", "]", "*", "(", "1.0", "-", "cosa", ")", ")", "+", "(", "axis", "[", "X", "]", "*", "sina", ")", ";", "mat", "[", "2", "]", "[", "2", "]", "=", "(", "axis", "[", "Z", "]", "*", "axis", "[", "Z", "]", ")", "+", "(", "(", "1.0", "-", "(", "axis", "[", "Z", "]", "*", "axis", "[", "Z", "]", ")", ")", "*", "cosa", ")", ";", "mat", "[", "2", "]", "[", "3", "]", "=", "0.0", ";", "mat", "[", "3", "]", "[", "0", "]", "=", "mat", "[", "3", "]", "[", "1", "]", "=", "mat", "[", "3", "]", "[", "2", "]", "=", "mat", "[", "3", "]", "[", "3", "]", "=", "0.0", ";", "vect_transform", "(", "v1", ",", "v2", ",", "mat", ")", ";", "}" ]
Rotate a vector about a specific axis
[ "Rotate", "a", "vector", "about", "a", "specific", "axis" ]
[]
[ { "param": "v1", "type": "Vector" }, { "param": "v2", "type": "Vector" }, { "param": "axis", "type": "Vector" }, { "param": "angle", "type": "float" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "v1", "type": "Vector", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "v2", "type": "Vector", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "axis", "type": "Vector", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "angle", "type": "float", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
404a3ab1808618bc18d75ef3f96ae6eaf67b2f25
kalyanam-FMTGA/ray-original
src/cv/vect3ds.c
[ "BSD-3-Clause-LBNL" ]
C
mat_rotate
void
void mat_rotate (Matrix mat1, Matrix mat2, int axis, float angle) { Matrix mat; float cosa, sina; cosa = cos ((PI/180.0) * angle); sina = sin ((PI/180.0) * angle); mat_identity (mat); switch (axis) { case X: mat[1][1] = cosa; mat[1][2] = sina; mat[2][1] = -sina; mat[2][2] = cosa; break; case Y: mat[0][0] = cosa; mat[0][2] = -sina; mat[2][0] = sina; mat[2][2] = cosa; break; case Z: mat[0][0] = cosa; mat[0][1] = sina; mat[1][0] = -sina; mat[1][1] = cosa; break; } mat_mult (mat1, mat2, mat); }
/* Rotate a matrix about the X, Y or Z axis */
Rotate a matrix about the X, Y or Z axis
[ "Rotate", "a", "matrix", "about", "the", "X", "Y", "or", "Z", "axis" ]
void mat_rotate (Matrix mat1, Matrix mat2, int axis, float angle) { Matrix mat; float cosa, sina; cosa = cos ((PI/180.0) * angle); sina = sin ((PI/180.0) * angle); mat_identity (mat); switch (axis) { case X: mat[1][1] = cosa; mat[1][2] = sina; mat[2][1] = -sina; mat[2][2] = cosa; break; case Y: mat[0][0] = cosa; mat[0][2] = -sina; mat[2][0] = sina; mat[2][2] = cosa; break; case Z: mat[0][0] = cosa; mat[0][1] = sina; mat[1][0] = -sina; mat[1][1] = cosa; break; } mat_mult (mat1, mat2, mat); }
[ "void", "mat_rotate", "(", "Matrix", "mat1", ",", "Matrix", "mat2", ",", "int", "axis", ",", "float", "angle", ")", "{", "Matrix", "mat", ";", "float", "cosa", ",", "sina", ";", "cosa", "=", "cos", "(", "(", "PI", "/", "180.0", ")", "*", "angle", ")", ";", "sina", "=", "sin", "(", "(", "PI", "/", "180.0", ")", "*", "angle", ")", ";", "mat_identity", "(", "mat", ")", ";", "switch", "(", "axis", ")", "{", "case", "X", ":", "mat", "[", "1", "]", "[", "1", "]", "=", "cosa", ";", "mat", "[", "1", "]", "[", "2", "]", "=", "sina", ";", "mat", "[", "2", "]", "[", "1", "]", "=", "-", "sina", ";", "mat", "[", "2", "]", "[", "2", "]", "=", "cosa", ";", "break", ";", "case", "Y", ":", "mat", "[", "0", "]", "[", "0", "]", "=", "cosa", ";", "mat", "[", "0", "]", "[", "2", "]", "=", "-", "sina", ";", "mat", "[", "2", "]", "[", "0", "]", "=", "sina", ";", "mat", "[", "2", "]", "[", "2", "]", "=", "cosa", ";", "break", ";", "case", "Z", ":", "mat", "[", "0", "]", "[", "0", "]", "=", "cosa", ";", "mat", "[", "0", "]", "[", "1", "]", "=", "sina", ";", "mat", "[", "1", "]", "[", "0", "]", "=", "-", "sina", ";", "mat", "[", "1", "]", "[", "1", "]", "=", "cosa", ";", "break", ";", "}", "mat_mult", "(", "mat1", ",", "mat2", ",", "mat", ")", ";", "}" ]
Rotate a matrix about the X, Y or Z axis
[ "Rotate", "a", "matrix", "about", "the", "X", "Y", "or", "Z", "axis" ]
[]
[ { "param": "mat1", "type": "Matrix" }, { "param": "mat2", "type": "Matrix" }, { "param": "axis", "type": "int" }, { "param": "angle", "type": "float" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "mat1", "type": "Matrix", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "mat2", "type": "Matrix", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "axis", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "angle", "type": "float", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
404a3ab1808618bc18d75ef3f96ae6eaf67b2f25
kalyanam-FMTGA/ray-original
src/cv/vect3ds.c
[ "BSD-3-Clause-LBNL" ]
C
mat_decode
void
void mat_decode (Matrix mat, Vector scale, Vector shear, Vector rotate, Vector transl) { int i; Vector row[3], temp; for (i = 0; i < 3; i++) transl[i] = mat[3][i]; for (i = 0; i < 3; i++) { row[i][X] = mat[i][0]; row[i][Y] = mat[i][1]; row[i][Z] = mat[i][2]; } scale[X] = vect_mag (row[0]); vect_normalize (row[0]); shear[X] = vect_dot (row[0], row[1]); row[1][X] = row[1][X] - shear[X]*row[0][X]; row[1][Y] = row[1][Y] - shear[X]*row[0][Y]; row[1][Z] = row[1][Z] - shear[X]*row[0][Z]; scale[Y] = vect_mag (row[1]); vect_normalize (row[1]); if (scale[Y] != 0.0) shear[X] /= scale[Y]; shear[Y] = vect_dot (row[0], row[2]); row[2][X] = row[2][X] - shear[Y]*row[0][X]; row[2][Y] = row[2][Y] - shear[Y]*row[0][Y]; row[2][Z] = row[2][Z] - shear[Y]*row[0][Z]; shear[Z] = vect_dot (row[1], row[2]); row[2][X] = row[2][X] - shear[Z]*row[1][X]; row[2][Y] = row[2][Y] - shear[Z]*row[1][Y]; row[2][Z] = row[2][Z] - shear[Z]*row[1][Z]; scale[Z] = vect_mag (row[2]); vect_normalize (row[2]); if (scale[Z] != 0.0) { shear[Y] /= scale[Z]; shear[Z] /= scale[Z]; } vect_cross (temp, row[1], row[2]); if (vect_dot (row[0], temp) < 0.0) { for (i = 0; i < 3; i++) { scale[i] *= -1.0; row[i][X] *= -1.0; row[i][Y] *= -1.0; row[i][Z] *= -1.0; } } if (row[0][Z] < -1.0) row[0][Z] = -1.0; if (row[0][Z] > +1.0) row[0][Z] = +1.0; rotate[Y] = asin(-row[0][Z]); if (fabs(cos(rotate[Y])) > EPSILON) { rotate[X] = atan2 (row[1][Z], row[2][Z]); rotate[Z] = atan2 (row[0][Y], row[0][X]); } else { rotate[X] = atan2 (row[1][X], row[1][Y]); rotate[Z] = 0.0; } /* Convert the rotations to degrees */ rotate[X] = (180.0/PI)*rotate[X]; rotate[Y] = (180.0/PI)*rotate[Y]; rotate[Z] = (180.0/PI)*rotate[Z]; }
/* Decodes a 3x4 transformation matrix into separate scale, rotation, translation, and shear vectors. Based on a program by Spencer W. Thomas (Graphics Gems II) */
Decodes a 3x4 transformation matrix into separate scale, rotation, translation, and shear vectors. Based on a program by Spencer W. Thomas (Graphics Gems II)
[ "Decodes", "a", "3x4", "transformation", "matrix", "into", "separate", "scale", "rotation", "translation", "and", "shear", "vectors", ".", "Based", "on", "a", "program", "by", "Spencer", "W", ".", "Thomas", "(", "Graphics", "Gems", "II", ")" ]
void mat_decode (Matrix mat, Vector scale, Vector shear, Vector rotate, Vector transl) { int i; Vector row[3], temp; for (i = 0; i < 3; i++) transl[i] = mat[3][i]; for (i = 0; i < 3; i++) { row[i][X] = mat[i][0]; row[i][Y] = mat[i][1]; row[i][Z] = mat[i][2]; } scale[X] = vect_mag (row[0]); vect_normalize (row[0]); shear[X] = vect_dot (row[0], row[1]); row[1][X] = row[1][X] - shear[X]*row[0][X]; row[1][Y] = row[1][Y] - shear[X]*row[0][Y]; row[1][Z] = row[1][Z] - shear[X]*row[0][Z]; scale[Y] = vect_mag (row[1]); vect_normalize (row[1]); if (scale[Y] != 0.0) shear[X] /= scale[Y]; shear[Y] = vect_dot (row[0], row[2]); row[2][X] = row[2][X] - shear[Y]*row[0][X]; row[2][Y] = row[2][Y] - shear[Y]*row[0][Y]; row[2][Z] = row[2][Z] - shear[Y]*row[0][Z]; shear[Z] = vect_dot (row[1], row[2]); row[2][X] = row[2][X] - shear[Z]*row[1][X]; row[2][Y] = row[2][Y] - shear[Z]*row[1][Y]; row[2][Z] = row[2][Z] - shear[Z]*row[1][Z]; scale[Z] = vect_mag (row[2]); vect_normalize (row[2]); if (scale[Z] != 0.0) { shear[Y] /= scale[Z]; shear[Z] /= scale[Z]; } vect_cross (temp, row[1], row[2]); if (vect_dot (row[0], temp) < 0.0) { for (i = 0; i < 3; i++) { scale[i] *= -1.0; row[i][X] *= -1.0; row[i][Y] *= -1.0; row[i][Z] *= -1.0; } } if (row[0][Z] < -1.0) row[0][Z] = -1.0; if (row[0][Z] > +1.0) row[0][Z] = +1.0; rotate[Y] = asin(-row[0][Z]); if (fabs(cos(rotate[Y])) > EPSILON) { rotate[X] = atan2 (row[1][Z], row[2][Z]); rotate[Z] = atan2 (row[0][Y], row[0][X]); } else { rotate[X] = atan2 (row[1][X], row[1][Y]); rotate[Z] = 0.0; } rotate[X] = (180.0/PI)*rotate[X]; rotate[Y] = (180.0/PI)*rotate[Y]; rotate[Z] = (180.0/PI)*rotate[Z]; }
[ "void", "mat_decode", "(", "Matrix", "mat", ",", "Vector", "scale", ",", "Vector", "shear", ",", "Vector", "rotate", ",", "Vector", "transl", ")", "{", "int", "i", ";", "Vector", "row", "[", "3", "]", ",", "temp", ";", "for", "(", "i", "=", "0", ";", "i", "<", "3", ";", "i", "++", ")", "transl", "[", "i", "]", "=", "mat", "[", "3", "]", "[", "i", "]", ";", "for", "(", "i", "=", "0", ";", "i", "<", "3", ";", "i", "++", ")", "{", "row", "[", "i", "]", "[", "X", "]", "=", "mat", "[", "i", "]", "[", "0", "]", ";", "row", "[", "i", "]", "[", "Y", "]", "=", "mat", "[", "i", "]", "[", "1", "]", ";", "row", "[", "i", "]", "[", "Z", "]", "=", "mat", "[", "i", "]", "[", "2", "]", ";", "}", "scale", "[", "X", "]", "=", "vect_mag", "(", "row", "[", "0", "]", ")", ";", "vect_normalize", "(", "row", "[", "0", "]", ")", ";", "shear", "[", "X", "]", "=", "vect_dot", "(", "row", "[", "0", "]", ",", "row", "[", "1", "]", ")", ";", "row", "[", "1", "]", "[", "X", "]", "=", "row", "[", "1", "]", "[", "X", "]", "-", "shear", "[", "X", "]", "*", "row", "[", "0", "]", "[", "X", "]", ";", "row", "[", "1", "]", "[", "Y", "]", "=", "row", "[", "1", "]", "[", "Y", "]", "-", "shear", "[", "X", "]", "*", "row", "[", "0", "]", "[", "Y", "]", ";", "row", "[", "1", "]", "[", "Z", "]", "=", "row", "[", "1", "]", "[", "Z", "]", "-", "shear", "[", "X", "]", "*", "row", "[", "0", "]", "[", "Z", "]", ";", "scale", "[", "Y", "]", "=", "vect_mag", "(", "row", "[", "1", "]", ")", ";", "vect_normalize", "(", "row", "[", "1", "]", ")", ";", "if", "(", "scale", "[", "Y", "]", "!=", "0.0", ")", "shear", "[", "X", "]", "/=", "scale", "[", "Y", "]", ";", "shear", "[", "Y", "]", "=", "vect_dot", "(", "row", "[", "0", "]", ",", "row", "[", "2", "]", ")", ";", "row", "[", "2", "]", "[", "X", "]", "=", "row", "[", "2", "]", "[", "X", "]", "-", "shear", "[", "Y", "]", "*", "row", "[", "0", "]", "[", "X", "]", ";", "row", "[", "2", "]", "[", "Y", "]", "=", "row", "[", "2", "]", "[", "Y", "]", "-", "shear", "[", "Y", "]", "*", "row", "[", "0", "]", "[", "Y", "]", ";", "row", "[", "2", "]", "[", "Z", "]", "=", "row", "[", "2", "]", "[", "Z", "]", "-", "shear", "[", "Y", "]", "*", "row", "[", "0", "]", "[", "Z", "]", ";", "shear", "[", "Z", "]", "=", "vect_dot", "(", "row", "[", "1", "]", ",", "row", "[", "2", "]", ")", ";", "row", "[", "2", "]", "[", "X", "]", "=", "row", "[", "2", "]", "[", "X", "]", "-", "shear", "[", "Z", "]", "*", "row", "[", "1", "]", "[", "X", "]", ";", "row", "[", "2", "]", "[", "Y", "]", "=", "row", "[", "2", "]", "[", "Y", "]", "-", "shear", "[", "Z", "]", "*", "row", "[", "1", "]", "[", "Y", "]", ";", "row", "[", "2", "]", "[", "Z", "]", "=", "row", "[", "2", "]", "[", "Z", "]", "-", "shear", "[", "Z", "]", "*", "row", "[", "1", "]", "[", "Z", "]", ";", "scale", "[", "Z", "]", "=", "vect_mag", "(", "row", "[", "2", "]", ")", ";", "vect_normalize", "(", "row", "[", "2", "]", ")", ";", "if", "(", "scale", "[", "Z", "]", "!=", "0.0", ")", "{", "shear", "[", "Y", "]", "/=", "scale", "[", "Z", "]", ";", "shear", "[", "Z", "]", "/=", "scale", "[", "Z", "]", ";", "}", "vect_cross", "(", "temp", ",", "row", "[", "1", "]", ",", "row", "[", "2", "]", ")", ";", "if", "(", "vect_dot", "(", "row", "[", "0", "]", ",", "temp", ")", "<", "0.0", ")", "{", "for", "(", "i", "=", "0", ";", "i", "<", "3", ";", "i", "++", ")", "{", "scale", "[", "i", "]", "*=", "-1.0", ";", "row", "[", "i", "]", "[", "X", "]", "*=", "-1.0", ";", "row", "[", "i", "]", "[", "Y", "]", "*=", "-1.0", ";", "row", "[", "i", "]", "[", "Z", "]", "*=", "-1.0", ";", "}", "}", "if", "(", "row", "[", "0", "]", "[", "Z", "]", "<", "-1.0", ")", "row", "[", "0", "]", "[", "Z", "]", "=", "-1.0", ";", "if", "(", "row", "[", "0", "]", "[", "Z", "]", ">", "+1.0", ")", "row", "[", "0", "]", "[", "Z", "]", "=", "+1.0", ";", "rotate", "[", "Y", "]", "=", "asin", "(", "-", "row", "[", "0", "]", "[", "Z", "]", ")", ";", "if", "(", "fabs", "(", "cos", "(", "rotate", "[", "Y", "]", ")", ")", ">", "EPSILON", ")", "{", "rotate", "[", "X", "]", "=", "atan2", "(", "row", "[", "1", "]", "[", "Z", "]", ",", "row", "[", "2", "]", "[", "Z", "]", ")", ";", "rotate", "[", "Z", "]", "=", "atan2", "(", "row", "[", "0", "]", "[", "Y", "]", ",", "row", "[", "0", "]", "[", "X", "]", ")", ";", "}", "else", "{", "rotate", "[", "X", "]", "=", "atan2", "(", "row", "[", "1", "]", "[", "X", "]", ",", "row", "[", "1", "]", "[", "Y", "]", ")", ";", "rotate", "[", "Z", "]", "=", "0.0", ";", "}", "rotate", "[", "X", "]", "=", "(", "180.0", "/", "PI", ")", "*", "rotate", "[", "X", "]", ";", "rotate", "[", "Y", "]", "=", "(", "180.0", "/", "PI", ")", "*", "rotate", "[", "Y", "]", ";", "rotate", "[", "Z", "]", "=", "(", "180.0", "/", "PI", ")", "*", "rotate", "[", "Z", "]", ";", "}" ]
Decodes a 3x4 transformation matrix into separate scale, rotation, translation, and shear vectors.
[ "Decodes", "a", "3x4", "transformation", "matrix", "into", "separate", "scale", "rotation", "translation", "and", "shear", "vectors", "." ]
[ "/* Convert the rotations to degrees */" ]
[ { "param": "mat", "type": "Matrix" }, { "param": "scale", "type": "Vector" }, { "param": "shear", "type": "Vector" }, { "param": "rotate", "type": "Vector" }, { "param": "transl", "type": "Vector" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "mat", "type": "Matrix", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "scale", "type": "Vector", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "shear", "type": "Vector", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "rotate", "type": "Vector", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "transl", "type": "Vector", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
40911b642c08545e7d2d7bfbf9c45d0210b9822f
kalyanam-FMTGA/ray-original
src/cv/pabopto2bsdf.c
[ "BSD-3-Clause-LBNL" ]
C
load_pabopto_meas
int
static int load_pabopto_meas(const char *fname) { FILE *fp = fopen(fname, "r"); int inp_is_DSF = -1; double new_theta, new_phi, theta_out, phi_out, val; char buf[2048]; int n, c; if (fp == NULL) { fputs(fname, stderr); fputs(": cannot open\n", stderr); return(0); } #ifdef DEBUG fprintf(stderr, "Loading measurement file '%s'...\n", fname); #endif /* read header information */ while ((c = getc(fp)) == '#' || c == EOF) { if (fgets(buf, sizeof(buf), fp) == NULL) { fputs(fname, stderr); fputs(": unexpected EOF\n", stderr); fclose(fp); return(0); } if (!strcmp(buf, "format: theta phi DSF\n")) { inp_is_DSF = 1; continue; } if (!strcmp(buf, "format: theta phi BSDF\n")) { inp_is_DSF = 0; continue; } if (sscanf(buf, "intheta %lf", &new_theta) == 1) continue; if (sscanf(buf, "inphi %lf", &new_phi) == 1) continue; if (sscanf(buf, "incident_angle %lf %lf", &new_theta, &new_phi) == 2) continue; } ungetc(c, fp); if (inp_is_DSF < 0) { fputs(fname, stderr); fputs(": unknown format\n", stderr); fclose(fp); return(0); } /* prepare input grid */ new_bsdf_data(new_theta, new_phi); /* read actual data */ while (fscanf(fp, "%lf %lf %lf\n", &theta_out, &phi_out, &val) == 3) add_bsdf_data(theta_out, phi_out, val, inp_is_DSF); n = 0; while ((c = getc(fp)) != EOF) n += !isspace(c); if (n) fprintf(stderr, "%s: warning: %d unexpected characters past EOD\n", fname, n); fclose(fp); return(1); }
/* Load a set of measurements corresponding to a particular incident angle */
Load a set of measurements corresponding to a particular incident angle
[ "Load", "a", "set", "of", "measurements", "corresponding", "to", "a", "particular", "incident", "angle" ]
static int load_pabopto_meas(const char *fname) { FILE *fp = fopen(fname, "r"); int inp_is_DSF = -1; double new_theta, new_phi, theta_out, phi_out, val; char buf[2048]; int n, c; if (fp == NULL) { fputs(fname, stderr); fputs(": cannot open\n", stderr); return(0); } #ifdef DEBUG fprintf(stderr, "Loading measurement file '%s'...\n", fname); #endif while ((c = getc(fp)) == '#' || c == EOF) { if (fgets(buf, sizeof(buf), fp) == NULL) { fputs(fname, stderr); fputs(": unexpected EOF\n", stderr); fclose(fp); return(0); } if (!strcmp(buf, "format: theta phi DSF\n")) { inp_is_DSF = 1; continue; } if (!strcmp(buf, "format: theta phi BSDF\n")) { inp_is_DSF = 0; continue; } if (sscanf(buf, "intheta %lf", &new_theta) == 1) continue; if (sscanf(buf, "inphi %lf", &new_phi) == 1) continue; if (sscanf(buf, "incident_angle %lf %lf", &new_theta, &new_phi) == 2) continue; } ungetc(c, fp); if (inp_is_DSF < 0) { fputs(fname, stderr); fputs(": unknown format\n", stderr); fclose(fp); return(0); } new_bsdf_data(new_theta, new_phi); while (fscanf(fp, "%lf %lf %lf\n", &theta_out, &phi_out, &val) == 3) add_bsdf_data(theta_out, phi_out, val, inp_is_DSF); n = 0; while ((c = getc(fp)) != EOF) n += !isspace(c); if (n) fprintf(stderr, "%s: warning: %d unexpected characters past EOD\n", fname, n); fclose(fp); return(1); }
[ "static", "int", "load_pabopto_meas", "(", "const", "char", "*", "fname", ")", "{", "FILE", "*", "fp", "=", "fopen", "(", "fname", ",", "\"", "\"", ")", ";", "int", "inp_is_DSF", "=", "-1", ";", "double", "new_theta", ",", "new_phi", ",", "theta_out", ",", "phi_out", ",", "val", ";", "char", "buf", "[", "2048", "]", ";", "int", "n", ",", "c", ";", "if", "(", "fp", "==", "NULL", ")", "{", "fputs", "(", "fname", ",", "stderr", ")", ";", "fputs", "(", "\"", "\\n", "\"", ",", "stderr", ")", ";", "return", "(", "0", ")", ";", "}", "#ifdef", "DEBUG", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "fname", ")", ";", "#endif", "while", "(", "(", "c", "=", "getc", "(", "fp", ")", ")", "==", "'", "'", "||", "c", "==", "EOF", ")", "{", "if", "(", "fgets", "(", "buf", ",", "sizeof", "(", "buf", ")", ",", "fp", ")", "==", "NULL", ")", "{", "fputs", "(", "fname", ",", "stderr", ")", ";", "fputs", "(", "\"", "\\n", "\"", ",", "stderr", ")", ";", "fclose", "(", "fp", ")", ";", "return", "(", "0", ")", ";", "}", "if", "(", "!", "strcmp", "(", "buf", ",", "\"", "\\n", "\"", ")", ")", "{", "inp_is_DSF", "=", "1", ";", "continue", ";", "}", "if", "(", "!", "strcmp", "(", "buf", ",", "\"", "\\n", "\"", ")", ")", "{", "inp_is_DSF", "=", "0", ";", "continue", ";", "}", "if", "(", "sscanf", "(", "buf", ",", "\"", "\"", ",", "&", "new_theta", ")", "==", "1", ")", "continue", ";", "if", "(", "sscanf", "(", "buf", ",", "\"", "\"", ",", "&", "new_phi", ")", "==", "1", ")", "continue", ";", "if", "(", "sscanf", "(", "buf", ",", "\"", "\"", ",", "&", "new_theta", ",", "&", "new_phi", ")", "==", "2", ")", "continue", ";", "}", "ungetc", "(", "c", ",", "fp", ")", ";", "if", "(", "inp_is_DSF", "<", "0", ")", "{", "fputs", "(", "fname", ",", "stderr", ")", ";", "fputs", "(", "\"", "\\n", "\"", ",", "stderr", ")", ";", "fclose", "(", "fp", ")", ";", "return", "(", "0", ")", ";", "}", "new_bsdf_data", "(", "new_theta", ",", "new_phi", ")", ";", "while", "(", "fscanf", "(", "fp", ",", "\"", "\\n", "\"", ",", "&", "theta_out", ",", "&", "phi_out", ",", "&", "val", ")", "==", "3", ")", "add_bsdf_data", "(", "theta_out", ",", "phi_out", ",", "val", ",", "inp_is_DSF", ")", ";", "n", "=", "0", ";", "while", "(", "(", "c", "=", "getc", "(", "fp", ")", ")", "!=", "EOF", ")", "n", "+=", "!", "isspace", "(", "c", ")", ";", "if", "(", "n", ")", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "fname", ",", "n", ")", ";", "fclose", "(", "fp", ")", ";", "return", "(", "1", ")", ";", "}" ]
Load a set of measurements corresponding to a particular incident angle
[ "Load", "a", "set", "of", "measurements", "corresponding", "to", "a", "particular", "incident", "angle" ]
[ "/* read header information */", "/* prepare input grid */", "/* read actual data */" ]
[ { "param": "fname", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fname", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
476bda9778e90a3b4a7716ae3d64ff13aed4d2a3
kalyanam-FMTGA/ray-original
src/ot/o_face.c
[ "BSD-3-Clause-LBNL" ]
C
o_face
int
int o_face( /* determine if face intersects cube */ OBJREC *o, CUBE *cu ) { FVECT cumin, cumax; FVECT v1, v2; double d1, d2; int vloc; register FACE *f; register int i, j; /* get face arguments */ f = getface(o); if (f->area == 0.0) /* empty face */ return(O_MISS); /* compute cube boundaries */ for (j = 0; j < 3; j++) cumax[j] = (cumin[j] = cu->cuorg[j]-FTINY) + cu->cusize + 2.0*FTINY; vloc = ABOVE | BELOW; /* check vertices */ for (i = 0; i < f->nv; i++) if ( (j = plocate(VERTEX(f,i), cumin, cumax)) ) vloc &= j; else return(O_HIT); /* vertex inside */ if (vloc) /* all to one side */ return(O_MISS); for (i = 0; i < f->nv; i++) { /* check edges */ if ((j = i + 1) >= f->nv) j = 0; /* wrap around */ VCOPY(v1, VERTEX(f,i)); /* clip modifies */ VCOPY(v2, VERTEX(f,j)); /* the vertices! */ if (clip(v1, v2, cumin, cumax)) return(O_HIT); /* edge inside */ } /* see if cube cuts plane */ for (j = 0; j < 3; j++) if (f->norm[j] > 0.0) { v1[j] = cumin[j]; v2[j] = cumax[j]; } else { v1[j] = cumax[j]; v2[j] = cumin[j]; } if ((d1 = DOT(v1, f->norm) - f->offset) > FTINY) return(O_MISS); if ((d2 = DOT(v2, f->norm) - f->offset) < -FTINY) return(O_MISS); /* intersect face */ for (j = 0; j < 3; j++) v1[j] = (v1[j]*d2 - v2[j]*d1)/(d2 - d1); if (inface(v1, f)) return(O_HIT); return(O_MISS); /* no intersection */ }
/* * The algorithm for determining a face's intersection * with a cube is relatively straightforward: * * 1) Check to see if any vertices are inside the cube * (intersection). * * 2) Check to see if all vertices are to one side of * cube (no intersection). * * 3) Check to see if any portion of any edge is inside * cube (intersection). * * 4) Check to see if the cube cuts the plane of the * face and one of its edges passes through * the face (intersection). * * 5) If test 4 fails, we have no intersection. */
The algorithm for determining a face's intersection with a cube is relatively straightforward. 1) Check to see if any vertices are inside the cube (intersection). 2) Check to see if all vertices are to one side of cube (no intersection). 3) Check to see if any portion of any edge is inside cube (intersection). 4) Check to see if the cube cuts the plane of the face and one of its edges passes through the face (intersection). 5) If test 4 fails, we have no intersection.
[ "The", "algorithm", "for", "determining", "a", "face", "'", "s", "intersection", "with", "a", "cube", "is", "relatively", "straightforward", ".", "1", ")", "Check", "to", "see", "if", "any", "vertices", "are", "inside", "the", "cube", "(", "intersection", ")", ".", "2", ")", "Check", "to", "see", "if", "all", "vertices", "are", "to", "one", "side", "of", "cube", "(", "no", "intersection", ")", ".", "3", ")", "Check", "to", "see", "if", "any", "portion", "of", "any", "edge", "is", "inside", "cube", "(", "intersection", ")", ".", "4", ")", "Check", "to", "see", "if", "the", "cube", "cuts", "the", "plane", "of", "the", "face", "and", "one", "of", "its", "edges", "passes", "through", "the", "face", "(", "intersection", ")", ".", "5", ")", "If", "test", "4", "fails", "we", "have", "no", "intersection", "." ]
int o_face( OBJREC *o, CUBE *cu ) { FVECT cumin, cumax; FVECT v1, v2; double d1, d2; int vloc; register FACE *f; register int i, j; f = getface(o); if (f->area == 0.0) return(O_MISS); for (j = 0; j < 3; j++) cumax[j] = (cumin[j] = cu->cuorg[j]-FTINY) + cu->cusize + 2.0*FTINY; vloc = ABOVE | BELOW; for (i = 0; i < f->nv; i++) if ( (j = plocate(VERTEX(f,i), cumin, cumax)) ) vloc &= j; else return(O_HIT); if (vloc) return(O_MISS); for (i = 0; i < f->nv; i++) { if ((j = i + 1) >= f->nv) j = 0; VCOPY(v1, VERTEX(f,i)); VCOPY(v2, VERTEX(f,j)); if (clip(v1, v2, cumin, cumax)) return(O_HIT); } for (j = 0; j < 3; j++) if (f->norm[j] > 0.0) { v1[j] = cumin[j]; v2[j] = cumax[j]; } else { v1[j] = cumax[j]; v2[j] = cumin[j]; } if ((d1 = DOT(v1, f->norm) - f->offset) > FTINY) return(O_MISS); if ((d2 = DOT(v2, f->norm) - f->offset) < -FTINY) return(O_MISS); for (j = 0; j < 3; j++) v1[j] = (v1[j]*d2 - v2[j]*d1)/(d2 - d1); if (inface(v1, f)) return(O_HIT); return(O_MISS); }
[ "int", "o_face", "(", "OBJREC", "*", "o", ",", "CUBE", "*", "cu", ")", "{", "FVECT", "cumin", ",", "cumax", ";", "FVECT", "v1", ",", "v2", ";", "double", "d1", ",", "d2", ";", "int", "vloc", ";", "register", "FACE", "*", "f", ";", "register", "int", "i", ",", "j", ";", "f", "=", "getface", "(", "o", ")", ";", "if", "(", "f", "->", "area", "==", "0.0", ")", "return", "(", "O_MISS", ")", ";", "for", "(", "j", "=", "0", ";", "j", "<", "3", ";", "j", "++", ")", "cumax", "[", "j", "]", "=", "(", "cumin", "[", "j", "]", "=", "cu", "->", "cuorg", "[", "j", "]", "-", "FTINY", ")", "+", "cu", "->", "cusize", "+", "2.0", "*", "FTINY", ";", "vloc", "=", "ABOVE", "|", "BELOW", ";", "for", "(", "i", "=", "0", ";", "i", "<", "f", "->", "nv", ";", "i", "++", ")", "if", "(", "(", "j", "=", "plocate", "(", "VERTEX", "(", "f", ",", "i", ")", ",", "cumin", ",", "cumax", ")", ")", ")", "vloc", "&=", "j", ";", "else", "return", "(", "O_HIT", ")", ";", "if", "(", "vloc", ")", "return", "(", "O_MISS", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "f", "->", "nv", ";", "i", "++", ")", "{", "if", "(", "(", "j", "=", "i", "+", "1", ")", ">=", "f", "->", "nv", ")", "j", "=", "0", ";", "VCOPY", "(", "v1", ",", "VERTEX", "(", "f", ",", "i", ")", ")", ";", "VCOPY", "(", "v2", ",", "VERTEX", "(", "f", ",", "j", ")", ")", ";", "if", "(", "clip", "(", "v1", ",", "v2", ",", "cumin", ",", "cumax", ")", ")", "return", "(", "O_HIT", ")", ";", "}", "for", "(", "j", "=", "0", ";", "j", "<", "3", ";", "j", "++", ")", "if", "(", "f", "->", "norm", "[", "j", "]", ">", "0.0", ")", "{", "v1", "[", "j", "]", "=", "cumin", "[", "j", "]", ";", "v2", "[", "j", "]", "=", "cumax", "[", "j", "]", ";", "}", "else", "{", "v1", "[", "j", "]", "=", "cumax", "[", "j", "]", ";", "v2", "[", "j", "]", "=", "cumin", "[", "j", "]", ";", "}", "if", "(", "(", "d1", "=", "DOT", "(", "v1", ",", "f", "->", "norm", ")", "-", "f", "->", "offset", ")", ">", "FTINY", ")", "return", "(", "O_MISS", ")", ";", "if", "(", "(", "d2", "=", "DOT", "(", "v2", ",", "f", "->", "norm", ")", "-", "f", "->", "offset", ")", "<", "-", "FTINY", ")", "return", "(", "O_MISS", ")", ";", "for", "(", "j", "=", "0", ";", "j", "<", "3", ";", "j", "++", ")", "v1", "[", "j", "]", "=", "(", "v1", "[", "j", "]", "*", "d2", "-", "v2", "[", "j", "]", "*", "d1", ")", "/", "(", "d2", "-", "d1", ")", ";", "if", "(", "inface", "(", "v1", ",", "f", ")", ")", "return", "(", "O_HIT", ")", ";", "return", "(", "O_MISS", ")", ";", "}" ]
The algorithm for determining a face's intersection with a cube is relatively straightforward:
[ "The", "algorithm", "for", "determining", "a", "face", "'", "s", "intersection", "with", "a", "cube", "is", "relatively", "straightforward", ":" ]
[ "/* determine if face intersects cube */", "/* get face arguments */", "/* empty face */", "/* compute cube boundaries */", "/* check vertices */", "/* vertex inside */", "/* all to one side */", "/* check edges */", "/* wrap around */", "/* clip modifies */", "/* the vertices! */", "/* edge inside */", "/* see if cube cuts plane */", "/* intersect face */", "/* no intersection */" ]
[ { "param": "o", "type": "OBJREC" }, { "param": "cu", "type": "CUBE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "o", "type": "OBJREC", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cu", "type": "CUBE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
efae943803327cf6fdb60e2ef20363ef917cb543
kalyanam-FMTGA/ray-original
src/rt/mx_data.c
[ "BSD-3-Clause-LBNL" ]
C
mx_data
int
extern int mx_data( /* interpolate mixture data */ register OBJREC *m, RAY *r ) { OBJECT obj; double coef; double pt[MAXDIM]; DATARRAY *dp; OBJECT mod[2]; register MFUNC *mf; register int i; if (m->oargs.nsargs < 6) objerror(m, USER, "bad # arguments"); obj = objndx(m); for (i = 0; i < 2; i++) if (!strcmp(m->oargs.sarg[i], VOIDID)) mod[i] = OVOID; else if ((mod[i] = lastmod(obj, m->oargs.sarg[i])) == OVOID) { sprintf(errmsg, "undefined modifier \"%s\"", m->oargs.sarg[i]); objerror(m, USER, errmsg); } dp = getdata(m->oargs.sarg[3]); i = (1 << dp->nd) - 1; mf = getfunc(m, 4, i<<5, 0); setfunc(m, r); errno = 0; for (i = 0; i < dp->nd; i++) { pt[i] = evalue(mf->ep[i]); if (errno == EDOM || errno == ERANGE) goto computerr; } coef = datavalue(dp, pt); errno = 0; coef = funvalue(m->oargs.sarg[2], 1, &coef); if (errno == EDOM || errno == ERANGE) goto computerr; if (raymixture(r, mod[0], mod[1], coef)) { if (m->omod != OVOID) objerror(m, USER, "inappropriate modifier"); return(1); } return(0); computerr: objerror(m, WARNING, "compute error"); return(0); }
/* * A stored mixture is specified: * * modifier mixdata name * 6+ foremod backmod func dfname vfname v0 v1 .. xf * 0 * n A1 A2 .. * * A picture mixture is specified as: * * modifier mixpict name * 7+ foremod backmod func pfname vfname vx vy xf * 0 * n A1 A2 .. * * * Vfname is the name of the file where the variable definitions * can be found. The list of real arguments can be accessed by * definitions in the file. Dfname is the data file. * (Pfname is a picture file.) * The dimensions of the data files and the number * of variables must match. The func is a single argument * function in the case of mixdata (three argument in the case * of mixpict), which returns the corrected data value given the * interpolated value from the file. The xf is a transformation * to get from the original coordinates to the current coordinates. */
A stored mixture is specified: modifier mixdata name 6+ foremod backmod func dfname vfname v0 v1 .. A picture mixture is specified as. modifier mixpict name 7+ foremod backmod func pfname vfname vx vy xf 0 n A1 A2 Vfname is the name of the file where the variable definitions can be found. The list of real arguments can be accessed by definitions in the file. Dfname is the data file. (Pfname is a picture file.) The dimensions of the data files and the number of variables must match. The func is a single argument function in the case of mixdata (three argument in the case of mixpict), which returns the corrected data value given the interpolated value from the file. The xf is a transformation to get from the original coordinates to the current coordinates.
[ "A", "stored", "mixture", "is", "specified", ":", "modifier", "mixdata", "name", "6", "+", "foremod", "backmod", "func", "dfname", "vfname", "v0", "v1", "..", "A", "picture", "mixture", "is", "specified", "as", ".", "modifier", "mixpict", "name", "7", "+", "foremod", "backmod", "func", "pfname", "vfname", "vx", "vy", "xf", "0", "n", "A1", "A2", "Vfname", "is", "the", "name", "of", "the", "file", "where", "the", "variable", "definitions", "can", "be", "found", ".", "The", "list", "of", "real", "arguments", "can", "be", "accessed", "by", "definitions", "in", "the", "file", ".", "Dfname", "is", "the", "data", "file", ".", "(", "Pfname", "is", "a", "picture", "file", ".", ")", "The", "dimensions", "of", "the", "data", "files", "and", "the", "number", "of", "variables", "must", "match", ".", "The", "func", "is", "a", "single", "argument", "function", "in", "the", "case", "of", "mixdata", "(", "three", "argument", "in", "the", "case", "of", "mixpict", ")", "which", "returns", "the", "corrected", "data", "value", "given", "the", "interpolated", "value", "from", "the", "file", ".", "The", "xf", "is", "a", "transformation", "to", "get", "from", "the", "original", "coordinates", "to", "the", "current", "coordinates", "." ]
extern int mx_data( register OBJREC *m, RAY *r ) { OBJECT obj; double coef; double pt[MAXDIM]; DATARRAY *dp; OBJECT mod[2]; register MFUNC *mf; register int i; if (m->oargs.nsargs < 6) objerror(m, USER, "bad # arguments"); obj = objndx(m); for (i = 0; i < 2; i++) if (!strcmp(m->oargs.sarg[i], VOIDID)) mod[i] = OVOID; else if ((mod[i] = lastmod(obj, m->oargs.sarg[i])) == OVOID) { sprintf(errmsg, "undefined modifier \"%s\"", m->oargs.sarg[i]); objerror(m, USER, errmsg); } dp = getdata(m->oargs.sarg[3]); i = (1 << dp->nd) - 1; mf = getfunc(m, 4, i<<5, 0); setfunc(m, r); errno = 0; for (i = 0; i < dp->nd; i++) { pt[i] = evalue(mf->ep[i]); if (errno == EDOM || errno == ERANGE) goto computerr; } coef = datavalue(dp, pt); errno = 0; coef = funvalue(m->oargs.sarg[2], 1, &coef); if (errno == EDOM || errno == ERANGE) goto computerr; if (raymixture(r, mod[0], mod[1], coef)) { if (m->omod != OVOID) objerror(m, USER, "inappropriate modifier"); return(1); } return(0); computerr: objerror(m, WARNING, "compute error"); return(0); }
[ "extern", "int", "mx_data", "(", "register", "OBJREC", "*", "m", ",", "RAY", "*", "r", ")", "{", "OBJECT", "obj", ";", "double", "coef", ";", "double", "pt", "[", "MAXDIM", "]", ";", "DATARRAY", "*", "dp", ";", "OBJECT", "mod", "[", "2", "]", ";", "register", "MFUNC", "*", "mf", ";", "register", "int", "i", ";", "if", "(", "m", "->", "oargs", ".", "nsargs", "<", "6", ")", "objerror", "(", "m", ",", "USER", ",", "\"", "\"", ")", ";", "obj", "=", "objndx", "(", "m", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "2", ";", "i", "++", ")", "if", "(", "!", "strcmp", "(", "m", "->", "oargs", ".", "sarg", "[", "i", "]", ",", "VOIDID", ")", ")", "mod", "[", "i", "]", "=", "OVOID", ";", "else", "if", "(", "(", "mod", "[", "i", "]", "=", "lastmod", "(", "obj", ",", "m", "->", "oargs", ".", "sarg", "[", "i", "]", ")", ")", "==", "OVOID", ")", "{", "sprintf", "(", "errmsg", ",", "\"", "\\\"", "\\\"", "\"", ",", "m", "->", "oargs", ".", "sarg", "[", "i", "]", ")", ";", "objerror", "(", "m", ",", "USER", ",", "errmsg", ")", ";", "}", "dp", "=", "getdata", "(", "m", "->", "oargs", ".", "sarg", "[", "3", "]", ")", ";", "i", "=", "(", "1", "<<", "dp", "->", "nd", ")", "-", "1", ";", "mf", "=", "getfunc", "(", "m", ",", "4", ",", "i", "<<", "5", ",", "0", ")", ";", "setfunc", "(", "m", ",", "r", ")", ";", "errno", "=", "0", ";", "for", "(", "i", "=", "0", ";", "i", "<", "dp", "->", "nd", ";", "i", "++", ")", "{", "pt", "[", "i", "]", "=", "evalue", "(", "mf", "->", "ep", "[", "i", "]", ")", ";", "if", "(", "errno", "==", "EDOM", "||", "errno", "==", "ERANGE", ")", "goto", "computerr", ";", "}", "coef", "=", "datavalue", "(", "dp", ",", "pt", ")", ";", "errno", "=", "0", ";", "coef", "=", "funvalue", "(", "m", "->", "oargs", ".", "sarg", "[", "2", "]", ",", "1", ",", "&", "coef", ")", ";", "if", "(", "errno", "==", "EDOM", "||", "errno", "==", "ERANGE", ")", "goto", "computerr", ";", "if", "(", "raymixture", "(", "r", ",", "mod", "[", "0", "]", ",", "mod", "[", "1", "]", ",", "coef", ")", ")", "{", "if", "(", "m", "->", "omod", "!=", "OVOID", ")", "objerror", "(", "m", ",", "USER", ",", "\"", "\"", ")", ";", "return", "(", "1", ")", ";", "}", "return", "(", "0", ")", ";", "computerr", ":", "objerror", "(", "m", ",", "WARNING", ",", "\"", "\"", ")", ";", "return", "(", "0", ")", ";", "}" ]
A stored mixture is specified: modifier mixdata name 6+ foremod backmod func dfname vfname v0 v1 .. xf 0 n A1 A2 ..
[ "A", "stored", "mixture", "is", "specified", ":", "modifier", "mixdata", "name", "6", "+", "foremod", "backmod", "func", "dfname", "vfname", "v0", "v1", "..", "xf", "0", "n", "A1", "A2", ".." ]
[ "/* interpolate mixture data */" ]
[ { "param": "m", "type": "OBJREC" }, { "param": "r", "type": "RAY" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "m", "type": "OBJREC", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "r", "type": "RAY", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c556e8ca25e5a64709eaaf65f09d326372e1e610
kalyanam-FMTGA/ray-original
src/common/tmaptiff.c
[ "BSD-3-Clause-LBNL" ]
C
tmMapTIFF
int
int tmMapTIFF(uby8 **psp, int *xp, int *yp, int flags, RGBPRIMP monpri, double gamval, double Lddyn, double Ldmax, char *fname, TIFF *tp) { char *funcName = fname==NULL ? "tmMapTIFF" : fname; TMstruct *tms = NULL; TMbright *lp; uby8 *cp; int err; /* check arguments */ if ((psp == NULL) | (xp == NULL) | (yp == NULL) | (monpri == NULL) | ((fname == NULL) & (tp == NULL))) returnErr(TM_E_ILLEGAL); if (gamval < MINGAM) gamval = DEFGAM; if (Lddyn < MINLDDYN) Lddyn = DEFLDDYN; if (Ldmax < MINLDMAX) Ldmax = DEFLDMAX; if (flags & TM_F_BW) monpri = stdprims; /* initialize tone mapping */ if ((tms = tmInit(flags, monpri, gamval)) == NULL) returnErr(TM_E_NOMEM); /* load and convert TIFF */ cp = TM_NOCHROM; err = tmLoadTIFF(tms, &lp, flags&TM_F_BW ? TM_NOCHROMP : &cp, xp, yp, fname, tp); if (err != TM_E_OK) { tmDone(tms); return(err); } if (cp == TM_NOCHROM) { *psp = (uby8 *)malloc(*xp * *yp * sizeof(uby8)); if (*psp == NULL) { free((MEM_PTR)lp); tmDone(tms); returnErr(TM_E_NOMEM); } } else *psp = cp; /* compute color mapping */ err = tmAddHisto(tms, lp, *xp * *yp, 1); if (err != TM_E_OK) goto done; err = tmComputeMapping(tms, gamval, Lddyn, Ldmax); if (err != TM_E_OK) goto done; /* map pixels */ err = tmMapPixels(tms, *psp, lp, cp, *xp * *yp); done: /* clean up */ free((MEM_PTR)lp); tmDone(tms); if (err != TM_E_OK) { /* free memory on error */ free((MEM_PTR)*psp); *psp = NULL; *xp = *yp = 0; returnErr(err); } returnOK; }
/* * Load and tone-map a SGILOG TIFF. * Beware of greyscale input -- you must check the PHOTOMETRIC tag to * determine that the returned array contains only grey values, not RGB. * As in tmMapPicture(), grey values are also returned if flags&TM_F_BW. */
Load and tone-map a SGILOG TIFF. Beware of greyscale input -- you must check the PHOTOMETRIC tag to determine that the returned array contains only grey values, not RGB. As in tmMapPicture(), grey values are also returned if flags&TM_F_BW.
[ "Load", "and", "tone", "-", "map", "a", "SGILOG", "TIFF", ".", "Beware", "of", "greyscale", "input", "--", "you", "must", "check", "the", "PHOTOMETRIC", "tag", "to", "determine", "that", "the", "returned", "array", "contains", "only", "grey", "values", "not", "RGB", ".", "As", "in", "tmMapPicture", "()", "grey", "values", "are", "also", "returned", "if", "flags&TM_F_BW", "." ]
int tmMapTIFF(uby8 **psp, int *xp, int *yp, int flags, RGBPRIMP monpri, double gamval, double Lddyn, double Ldmax, char *fname, TIFF *tp) { char *funcName = fname==NULL ? "tmMapTIFF" : fname; TMstruct *tms = NULL; TMbright *lp; uby8 *cp; int err; if ((psp == NULL) | (xp == NULL) | (yp == NULL) | (monpri == NULL) | ((fname == NULL) & (tp == NULL))) returnErr(TM_E_ILLEGAL); if (gamval < MINGAM) gamval = DEFGAM; if (Lddyn < MINLDDYN) Lddyn = DEFLDDYN; if (Ldmax < MINLDMAX) Ldmax = DEFLDMAX; if (flags & TM_F_BW) monpri = stdprims; if ((tms = tmInit(flags, monpri, gamval)) == NULL) returnErr(TM_E_NOMEM); cp = TM_NOCHROM; err = tmLoadTIFF(tms, &lp, flags&TM_F_BW ? TM_NOCHROMP : &cp, xp, yp, fname, tp); if (err != TM_E_OK) { tmDone(tms); return(err); } if (cp == TM_NOCHROM) { *psp = (uby8 *)malloc(*xp * *yp * sizeof(uby8)); if (*psp == NULL) { free((MEM_PTR)lp); tmDone(tms); returnErr(TM_E_NOMEM); } } else *psp = cp; err = tmAddHisto(tms, lp, *xp * *yp, 1); if (err != TM_E_OK) goto done; err = tmComputeMapping(tms, gamval, Lddyn, Ldmax); if (err != TM_E_OK) goto done; err = tmMapPixels(tms, *psp, lp, cp, *xp * *yp); done: free((MEM_PTR)lp); tmDone(tms); if (err != TM_E_OK) { free((MEM_PTR)*psp); *psp = NULL; *xp = *yp = 0; returnErr(err); } returnOK; }
[ "int", "tmMapTIFF", "(", "uby8", "*", "*", "psp", ",", "int", "*", "xp", ",", "int", "*", "yp", ",", "int", "flags", ",", "RGBPRIMP", "monpri", ",", "double", "gamval", ",", "double", "Lddyn", ",", "double", "Ldmax", ",", "char", "*", "fname", ",", "TIFF", "*", "tp", ")", "{", "char", "*", "funcName", "=", "fname", "==", "NULL", "?", "\"", "\"", ":", "fname", ";", "TMstruct", "*", "tms", "=", "NULL", ";", "TMbright", "*", "lp", ";", "uby8", "*", "cp", ";", "int", "err", ";", "if", "(", "(", "psp", "==", "NULL", ")", "|", "(", "xp", "==", "NULL", ")", "|", "(", "yp", "==", "NULL", ")", "|", "(", "monpri", "==", "NULL", ")", "|", "(", "(", "fname", "==", "NULL", ")", "&", "(", "tp", "==", "NULL", ")", ")", ")", "returnErr", "(", "TM_E_ILLEGAL", ")", ";", "if", "(", "gamval", "<", "MINGAM", ")", "gamval", "=", "DEFGAM", ";", "if", "(", "Lddyn", "<", "MINLDDYN", ")", "Lddyn", "=", "DEFLDDYN", ";", "if", "(", "Ldmax", "<", "MINLDMAX", ")", "Ldmax", "=", "DEFLDMAX", ";", "if", "(", "flags", "&", "TM_F_BW", ")", "monpri", "=", "stdprims", ";", "if", "(", "(", "tms", "=", "tmInit", "(", "flags", ",", "monpri", ",", "gamval", ")", ")", "==", "NULL", ")", "returnErr", "(", "TM_E_NOMEM", ")", ";", "cp", "=", "TM_NOCHROM", ";", "err", "=", "tmLoadTIFF", "(", "tms", ",", "&", "lp", ",", "flags", "&", "TM_F_BW", "?", "TM_NOCHROMP", ":", "&", "cp", ",", "xp", ",", "yp", ",", "fname", ",", "tp", ")", ";", "if", "(", "err", "!=", "TM_E_OK", ")", "{", "tmDone", "(", "tms", ")", ";", "return", "(", "err", ")", ";", "}", "if", "(", "cp", "==", "TM_NOCHROM", ")", "{", "*", "psp", "=", "(", "uby8", "*", ")", "malloc", "(", "*", "xp", "*", "*", "yp", "*", "sizeof", "(", "uby8", ")", ")", ";", "if", "(", "*", "psp", "==", "NULL", ")", "{", "free", "(", "(", "MEM_PTR", ")", "lp", ")", ";", "tmDone", "(", "tms", ")", ";", "returnErr", "(", "TM_E_NOMEM", ")", ";", "}", "}", "else", "*", "psp", "=", "cp", ";", "err", "=", "tmAddHisto", "(", "tms", ",", "lp", ",", "*", "xp", "*", "*", "yp", ",", "1", ")", ";", "if", "(", "err", "!=", "TM_E_OK", ")", "goto", "done", ";", "err", "=", "tmComputeMapping", "(", "tms", ",", "gamval", ",", "Lddyn", ",", "Ldmax", ")", ";", "if", "(", "err", "!=", "TM_E_OK", ")", "goto", "done", ";", "err", "=", "tmMapPixels", "(", "tms", ",", "*", "psp", ",", "lp", ",", "cp", ",", "*", "xp", "*", "*", "yp", ")", ";", "done", ":", "free", "(", "(", "MEM_PTR", ")", "lp", ")", ";", "tmDone", "(", "tms", ")", ";", "if", "(", "err", "!=", "TM_E_OK", ")", "{", "free", "(", "(", "MEM_PTR", ")", "*", "psp", ")", ";", "*", "psp", "=", "NULL", ";", "*", "xp", "=", "*", "yp", "=", "0", ";", "returnErr", "(", "err", ")", ";", "}", "returnOK", ";", "}" ]
Load and tone-map a SGILOG TIFF.
[ "Load", "and", "tone", "-", "map", "a", "SGILOG", "TIFF", "." ]
[ "/* check arguments */", "/* initialize tone mapping */", "/* load and convert TIFF */", "/* compute color mapping */", "/* map pixels */", "/* clean up */", "/* free memory on error */" ]
[ { "param": "psp", "type": "uby8" }, { "param": "xp", "type": "int" }, { "param": "yp", "type": "int" }, { "param": "flags", "type": "int" }, { "param": "monpri", "type": "RGBPRIMP" }, { "param": "gamval", "type": "double" }, { "param": "Lddyn", "type": "double" }, { "param": "Ldmax", "type": "double" }, { "param": "fname", "type": "char" }, { "param": "tp", "type": "TIFF" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "psp", "type": "uby8", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "xp", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "yp", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "flags", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "monpri", "type": "RGBPRIMP", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "gamval", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "Lddyn", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "Ldmax", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "fname", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "tp", "type": "TIFF", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a6c95d46c7283f6706245c98f25a833141707292
kalyanam-FMTGA/ray-original
src/common/bsdf_t.c
[ "BSD-3-Clause-LBNL" ]
C
SDFreeBTre
void
static void SDFreeBTre(void *p) { SDTre *sdt = (SDTre *)p; if (sdt == NULL) return; SDfreeTre(sdt->st); free(sdt); }
/* Free a variable-resolution BSDF */
Free a variable-resolution BSDF
[ "Free", "a", "variable", "-", "resolution", "BSDF" ]
static void SDFreeBTre(void *p) { SDTre *sdt = (SDTre *)p; if (sdt == NULL) return; SDfreeTre(sdt->st); free(sdt); }
[ "static", "void", "SDFreeBTre", "(", "void", "*", "p", ")", "{", "SDTre", "*", "sdt", "=", "(", "SDTre", "*", ")", "p", ";", "if", "(", "sdt", "==", "NULL", ")", "return", ";", "SDfreeTre", "(", "sdt", "->", "st", ")", ";", "free", "(", "sdt", ")", ";", "}" ]
Free a variable-resolution BSDF
[ "Free", "a", "variable", "-", "resolution", "BSDF" ]
[]
[ { "param": "p", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "p", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a6c95d46c7283f6706245c98f25a833141707292
kalyanam-FMTGA/ray-original
src/common/bsdf_t.c
[ "BSD-3-Clause-LBNL" ]
C
SDtraverseTre
int
static int SDtraverseTre(const SDNode *st, const double *pos, int cmask, SDtreCallback *cf, void *cptr) { static double czero[SD_MAXDIM]; int i; /* check arguments */ if ((st == NULL) | (cf == NULL)) return -1; for (i = st->ndim; i--; ) if (1<<i & cmask && (pos[i] < 0) | (pos[i] >= 1.)) return -1; return SDdotravTre(st, pos, cmask, cf, cptr, czero, 1.); }
/* Traverse a tree, visiting nodes in a slice that fits partial position */
Traverse a tree, visiting nodes in a slice that fits partial position
[ "Traverse", "a", "tree", "visiting", "nodes", "in", "a", "slice", "that", "fits", "partial", "position" ]
static int SDtraverseTre(const SDNode *st, const double *pos, int cmask, SDtreCallback *cf, void *cptr) { static double czero[SD_MAXDIM]; int i; if ((st == NULL) | (cf == NULL)) return -1; for (i = st->ndim; i--; ) if (1<<i & cmask && (pos[i] < 0) | (pos[i] >= 1.)) return -1; return SDdotravTre(st, pos, cmask, cf, cptr, czero, 1.); }
[ "static", "int", "SDtraverseTre", "(", "const", "SDNode", "*", "st", ",", "const", "double", "*", "pos", ",", "int", "cmask", ",", "SDtreCallback", "*", "cf", ",", "void", "*", "cptr", ")", "{", "static", "double", "czero", "[", "SD_MAXDIM", "]", ";", "int", "i", ";", "if", "(", "(", "st", "==", "NULL", ")", "|", "(", "cf", "==", "NULL", ")", ")", "return", "-1", ";", "for", "(", "i", "=", "st", "->", "ndim", ";", "i", "--", ";", ")", "if", "(", "1", "<<", "i", "&", "cmask", "&&", "(", "pos", "[", "i", "]", "<", "0", ")", "|", "(", "pos", "[", "i", "]", ">=", "1.", ")", ")", "return", "-1", ";", "return", "SDdotravTre", "(", "st", ",", "pos", ",", "cmask", ",", "cf", ",", "cptr", ",", "czero", ",", "1.", ")", ";", "}" ]
Traverse a tree, visiting nodes in a slice that fits partial position
[ "Traverse", "a", "tree", "visiting", "nodes", "in", "a", "slice", "that", "fits", "partial", "position" ]
[ "/* check arguments */" ]
[ { "param": "st", "type": "SDNode" }, { "param": "pos", "type": "double" }, { "param": "cmask", "type": "int" }, { "param": "cf", "type": "SDtreCallback" }, { "param": "cptr", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "st", "type": "SDNode", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pos", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cmask", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cf", "type": "SDtreCallback", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cptr", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a6c95d46c7283f6706245c98f25a833141707292
kalyanam-FMTGA/ray-original
src/common/bsdf_t.c
[ "BSD-3-Clause-LBNL" ]
C
SDlookupTre
float
static float SDlookupTre(const SDNode *st, const double *pos, double *hcube) { double spos[SD_MAXDIM]; int i, n, t; /* initialize voxel return */ if (hcube) { hcube[i = st->ndim] = 1.; while (i--) hcube[i] = .0; } /* climb the tree */ while (st->log2GR < 0) { n = 0; /* move to appropriate branch */ if (hcube) hcube[st->ndim] *= .5; for (i = st->ndim; i--; ) { spos[i] = 2.*pos[i]; t = (spos[i] >= 1.); n |= t<<i; spos[i] -= (double)t; if (hcube) hcube[i] += (double)t * hcube[st->ndim]; } st = st->u.t[n]; /* avoids tail recursion */ pos = spos; } if (st->log2GR == 0) /* short cut */ return st->u.v[0]; n = t = 0; /* find grid array index */ for (i = st->ndim; i--; ) { n += (int)((1<<st->log2GR)*pos[i]) << t; t += st->log2GR; } if (hcube) { /* compute final hypercube */ hcube[st->ndim] /= (double)(1<<st->log2GR); for (i = st->ndim; i--; ) hcube[i] += floor((1<<st->log2GR)*pos[i])*hcube[st->ndim]; } return st->u.v[n]; /* no interpolation */ }
/* Look up tree value at the given grid position */
Look up tree value at the given grid position
[ "Look", "up", "tree", "value", "at", "the", "given", "grid", "position" ]
static float SDlookupTre(const SDNode *st, const double *pos, double *hcube) { double spos[SD_MAXDIM]; int i, n, t; if (hcube) { hcube[i = st->ndim] = 1.; while (i--) hcube[i] = .0; } while (st->log2GR < 0) { n = 0; if (hcube) hcube[st->ndim] *= .5; for (i = st->ndim; i--; ) { spos[i] = 2.*pos[i]; t = (spos[i] >= 1.); n |= t<<i; spos[i] -= (double)t; if (hcube) hcube[i] += (double)t * hcube[st->ndim]; } st = st->u.t[n]; pos = spos; } if (st->log2GR == 0) return st->u.v[0]; n = t = 0; for (i = st->ndim; i--; ) { n += (int)((1<<st->log2GR)*pos[i]) << t; t += st->log2GR; } if (hcube) { hcube[st->ndim] /= (double)(1<<st->log2GR); for (i = st->ndim; i--; ) hcube[i] += floor((1<<st->log2GR)*pos[i])*hcube[st->ndim]; } return st->u.v[n]; }
[ "static", "float", "SDlookupTre", "(", "const", "SDNode", "*", "st", ",", "const", "double", "*", "pos", ",", "double", "*", "hcube", ")", "{", "double", "spos", "[", "SD_MAXDIM", "]", ";", "int", "i", ",", "n", ",", "t", ";", "if", "(", "hcube", ")", "{", "hcube", "[", "i", "=", "st", "->", "ndim", "]", "=", "1.", ";", "while", "(", "i", "--", ")", "hcube", "[", "i", "]", "=", ".0", ";", "}", "while", "(", "st", "->", "log2GR", "<", "0", ")", "{", "n", "=", "0", ";", "if", "(", "hcube", ")", "hcube", "[", "st", "->", "ndim", "]", "*=", ".5", ";", "for", "(", "i", "=", "st", "->", "ndim", ";", "i", "--", ";", ")", "{", "spos", "[", "i", "]", "=", "2.", "*", "pos", "[", "i", "]", ";", "t", "=", "(", "spos", "[", "i", "]", ">=", "1.", ")", ";", "n", "|=", "t", "<<", "i", ";", "spos", "[", "i", "]", "-=", "(", "double", ")", "t", ";", "if", "(", "hcube", ")", "hcube", "[", "i", "]", "+=", "(", "double", ")", "t", "*", "hcube", "[", "st", "->", "ndim", "]", ";", "}", "st", "=", "st", "->", "u", ".", "t", "[", "n", "]", ";", "pos", "=", "spos", ";", "}", "if", "(", "st", "->", "log2GR", "==", "0", ")", "return", "st", "->", "u", ".", "v", "[", "0", "]", ";", "n", "=", "t", "=", "0", ";", "for", "(", "i", "=", "st", "->", "ndim", ";", "i", "--", ";", ")", "{", "n", "+=", "(", "int", ")", "(", "(", "1", "<<", "st", "->", "log2GR", ")", "*", "pos", "[", "i", "]", ")", "<<", "t", ";", "t", "+=", "st", "->", "log2GR", ";", "}", "if", "(", "hcube", ")", "{", "hcube", "[", "st", "->", "ndim", "]", "/=", "(", "double", ")", "(", "1", "<<", "st", "->", "log2GR", ")", ";", "for", "(", "i", "=", "st", "->", "ndim", ";", "i", "--", ";", ")", "hcube", "[", "i", "]", "+=", "floor", "(", "(", "1", "<<", "st", "->", "log2GR", ")", "*", "pos", "[", "i", "]", ")", "*", "hcube", "[", "st", "->", "ndim", "]", ";", "}", "return", "st", "->", "u", ".", "v", "[", "n", "]", ";", "}" ]
Look up tree value at the given grid position
[ "Look", "up", "tree", "value", "at", "the", "given", "grid", "position" ]
[ "/* initialize voxel return */", "/* climb the tree */", "/* move to appropriate branch */", "/* avoids tail recursion */", "/* short cut */", "/* find grid array index */", "/* compute final hypercube */", "/* no interpolation */" ]
[ { "param": "st", "type": "SDNode" }, { "param": "pos", "type": "double" }, { "param": "hcube", "type": "double" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "st", "type": "SDNode", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pos", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "hcube", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a6c95d46c7283f6706245c98f25a833141707292
kalyanam-FMTGA/ray-original
src/common/bsdf_t.c
[ "BSD-3-Clause-LBNL" ]
C
SDqueryTre
float
static float SDqueryTre(const SDTre *sdt, const FVECT outVec, const FVECT inVec, double *hc) { const RREAL *vtmp; FVECT rOutVec; double gridPos[4]; switch (sdt->sidef) { /* whose side are you on? */ case SD_FREFL: if ((outVec[2] < 0) | (inVec[2] < 0)) return -1.; break; case SD_BREFL: if ((outVec[2] > 0) | (inVec[2] > 0)) return -1.; break; case SD_FXMIT: if (outVec[2] > 0) { if (inVec[2] > 0) return -1.; vtmp = outVec; outVec = inVec; inVec = vtmp; } else if (inVec[2] < 0) return -1.; break; case SD_BXMIT: if (inVec[2] > 0) { if (outVec[2] > 0) return -1.; vtmp = outVec; outVec = inVec; inVec = vtmp; } else if (outVec[2] < 0) return -1.; break; default: return -1.; } /* convert vector coordinates */ if (sdt->st->ndim == 3) { spinvector(rOutVec, outVec, zvec, -atan2(-inVec[1],-inVec[0])); gridPos[0] = .5 - .5*sqrt(inVec[0]*inVec[0] + inVec[1]*inVec[1]); SDdisk2square(gridPos+1, rOutVec[0], rOutVec[1]); } else if (sdt->st->ndim == 4) { SDdisk2square(gridPos, -inVec[0], -inVec[1]); SDdisk2square(gridPos+2, outVec[0], outVec[1]); } else return -1.; /* should be internal error */ return SDlookupTre(sdt->st, gridPos, hc); }
/* Query BSDF value and sample hypercube for the given vectors */
Query BSDF value and sample hypercube for the given vectors
[ "Query", "BSDF", "value", "and", "sample", "hypercube", "for", "the", "given", "vectors" ]
static float SDqueryTre(const SDTre *sdt, const FVECT outVec, const FVECT inVec, double *hc) { const RREAL *vtmp; FVECT rOutVec; double gridPos[4]; switch (sdt->sidef) { case SD_FREFL: if ((outVec[2] < 0) | (inVec[2] < 0)) return -1.; break; case SD_BREFL: if ((outVec[2] > 0) | (inVec[2] > 0)) return -1.; break; case SD_FXMIT: if (outVec[2] > 0) { if (inVec[2] > 0) return -1.; vtmp = outVec; outVec = inVec; inVec = vtmp; } else if (inVec[2] < 0) return -1.; break; case SD_BXMIT: if (inVec[2] > 0) { if (outVec[2] > 0) return -1.; vtmp = outVec; outVec = inVec; inVec = vtmp; } else if (outVec[2] < 0) return -1.; break; default: return -1.; } if (sdt->st->ndim == 3) { spinvector(rOutVec, outVec, zvec, -atan2(-inVec[1],-inVec[0])); gridPos[0] = .5 - .5*sqrt(inVec[0]*inVec[0] + inVec[1]*inVec[1]); SDdisk2square(gridPos+1, rOutVec[0], rOutVec[1]); } else if (sdt->st->ndim == 4) { SDdisk2square(gridPos, -inVec[0], -inVec[1]); SDdisk2square(gridPos+2, outVec[0], outVec[1]); } else return -1.; return SDlookupTre(sdt->st, gridPos, hc); }
[ "static", "float", "SDqueryTre", "(", "const", "SDTre", "*", "sdt", ",", "const", "FVECT", "outVec", ",", "const", "FVECT", "inVec", ",", "double", "*", "hc", ")", "{", "const", "RREAL", "*", "vtmp", ";", "FVECT", "rOutVec", ";", "double", "gridPos", "[", "4", "]", ";", "switch", "(", "sdt", "->", "sidef", ")", "{", "case", "SD_FREFL", ":", "if", "(", "(", "outVec", "[", "2", "]", "<", "0", ")", "|", "(", "inVec", "[", "2", "]", "<", "0", ")", ")", "return", "-1.", ";", "break", ";", "case", "SD_BREFL", ":", "if", "(", "(", "outVec", "[", "2", "]", ">", "0", ")", "|", "(", "inVec", "[", "2", "]", ">", "0", ")", ")", "return", "-1.", ";", "break", ";", "case", "SD_FXMIT", ":", "if", "(", "outVec", "[", "2", "]", ">", "0", ")", "{", "if", "(", "inVec", "[", "2", "]", ">", "0", ")", "return", "-1.", ";", "vtmp", "=", "outVec", ";", "outVec", "=", "inVec", ";", "inVec", "=", "vtmp", ";", "}", "else", "if", "(", "inVec", "[", "2", "]", "<", "0", ")", "return", "-1.", ";", "break", ";", "case", "SD_BXMIT", ":", "if", "(", "inVec", "[", "2", "]", ">", "0", ")", "{", "if", "(", "outVec", "[", "2", "]", ">", "0", ")", "return", "-1.", ";", "vtmp", "=", "outVec", ";", "outVec", "=", "inVec", ";", "inVec", "=", "vtmp", ";", "}", "else", "if", "(", "outVec", "[", "2", "]", "<", "0", ")", "return", "-1.", ";", "break", ";", "default", ":", "return", "-1.", ";", "}", "if", "(", "sdt", "->", "st", "->", "ndim", "==", "3", ")", "{", "spinvector", "(", "rOutVec", ",", "outVec", ",", "zvec", ",", "-", "atan2", "(", "-", "inVec", "[", "1", "]", ",", "-", "inVec", "[", "0", "]", ")", ")", ";", "gridPos", "[", "0", "]", "=", ".5", "-", ".5", "*", "sqrt", "(", "inVec", "[", "0", "]", "*", "inVec", "[", "0", "]", "+", "inVec", "[", "1", "]", "*", "inVec", "[", "1", "]", ")", ";", "SDdisk2square", "(", "gridPos", "+", "1", ",", "rOutVec", "[", "0", "]", ",", "rOutVec", "[", "1", "]", ")", ";", "}", "else", "if", "(", "sdt", "->", "st", "->", "ndim", "==", "4", ")", "{", "SDdisk2square", "(", "gridPos", ",", "-", "inVec", "[", "0", "]", ",", "-", "inVec", "[", "1", "]", ")", ";", "SDdisk2square", "(", "gridPos", "+", "2", ",", "outVec", "[", "0", "]", ",", "outVec", "[", "1", "]", ")", ";", "}", "else", "return", "-1.", ";", "return", "SDlookupTre", "(", "sdt", "->", "st", ",", "gridPos", ",", "hc", ")", ";", "}" ]
Query BSDF value and sample hypercube for the given vectors
[ "Query", "BSDF", "value", "and", "sample", "hypercube", "for", "the", "given", "vectors" ]
[ "/* whose side are you on? */", "/* convert vector coordinates */", "/* should be internal error */" ]
[ { "param": "sdt", "type": "SDTre" }, { "param": "outVec", "type": "FVECT" }, { "param": "inVec", "type": "FVECT" }, { "param": "hc", "type": "double" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sdt", "type": "SDTre", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "outVec", "type": "FVECT", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "inVec", "type": "FVECT", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "hc", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a6c95d46c7283f6706245c98f25a833141707292
kalyanam-FMTGA/ray-original
src/common/bsdf_t.c
[ "BSD-3-Clause-LBNL" ]
C
SDgetTreBSDF
int
static int SDgetTreBSDF(float coef[SDmaxCh], const FVECT outVec, const FVECT inVec, SDComponent *sdc) { /* check arguments */ if ((coef == NULL) | (outVec == NULL) | (inVec == NULL) | (sdc == NULL) || sdc->dist == NULL) return 0; /* get nearest BSDF value */ coef[0] = SDqueryTre((SDTre *)sdc->dist, outVec, inVec, NULL); return (coef[0] >= 0); /* monochromatic for now */ }
/* Compute non-diffuse component for variable-resolution BSDF */
Compute non-diffuse component for variable-resolution BSDF
[ "Compute", "non", "-", "diffuse", "component", "for", "variable", "-", "resolution", "BSDF" ]
static int SDgetTreBSDF(float coef[SDmaxCh], const FVECT outVec, const FVECT inVec, SDComponent *sdc) { if ((coef == NULL) | (outVec == NULL) | (inVec == NULL) | (sdc == NULL) || sdc->dist == NULL) return 0; coef[0] = SDqueryTre((SDTre *)sdc->dist, outVec, inVec, NULL); return (coef[0] >= 0); }
[ "static", "int", "SDgetTreBSDF", "(", "float", "coef", "[", "SDmaxCh", "]", ",", "const", "FVECT", "outVec", ",", "const", "FVECT", "inVec", ",", "SDComponent", "*", "sdc", ")", "{", "if", "(", "(", "coef", "==", "NULL", ")", "|", "(", "outVec", "==", "NULL", ")", "|", "(", "inVec", "==", "NULL", ")", "|", "(", "sdc", "==", "NULL", ")", "||", "sdc", "->", "dist", "==", "NULL", ")", "return", "0", ";", "coef", "[", "0", "]", "=", "SDqueryTre", "(", "(", "SDTre", "*", ")", "sdc", "->", "dist", ",", "outVec", ",", "inVec", ",", "NULL", ")", ";", "return", "(", "coef", "[", "0", "]", ">=", "0", ")", ";", "}" ]
Compute non-diffuse component for variable-resolution BSDF
[ "Compute", "non", "-", "diffuse", "component", "for", "variable", "-", "resolution", "BSDF" ]
[ "/* check arguments */", "/* get nearest BSDF value */", "/* monochromatic for now */" ]
[ { "param": "coef", "type": "float" }, { "param": "outVec", "type": "FVECT" }, { "param": "inVec", "type": "FVECT" }, { "param": "sdc", "type": "SDComponent" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "coef", "type": "float", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "outVec", "type": "FVECT", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "inVec", "type": "FVECT", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "sdc", "type": "SDComponent", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a6c95d46c7283f6706245c98f25a833141707292
kalyanam-FMTGA/ray-original
src/common/bsdf_t.c
[ "BSD-3-Clause-LBNL" ]
C
build_scaffold
int
static int build_scaffold(float val, const double *cmin, double csiz, void *cptr) { SDdistScaffold *sp = (SDdistScaffold *)cptr; int wid = csiz*(double)iwmax + .5; double revcmin[2]; bitmask_t bmin[2], bmax[2]; if (sp->rev) { /* need to reverse sense? */ revcmin[0] = 1. - cmin[0] - csiz; revcmin[1] = 1. - cmin[1] - csiz; cmin = revcmin; } else { cmin += sp->nic; /* else skip to output coords */ } if (wid < sp->wmin) /* new minimum width? */ sp->wmin = wid; if (wid > sp->wmax) /* new maximum? */ sp->wmax = wid; if (sp->alen >= sp->nall) { /* need more space? */ struct outdir_s *ndarr; sp->nall += 1024; ndarr = (struct outdir_s *)realloc(sp->darr, sizeof(struct outdir_s)*sp->nall); if (ndarr == NULL) { sprintf(SDerrorDetail, "Cannot grow scaffold to %u entries", sp->nall); return -1; /* abort build */ } sp->darr = ndarr; } /* find Hilbert entry index */ bmin[0] = cmin[0]*(double)iwmax + .5; bmin[1] = cmin[1]*(double)iwmax + .5; bmax[0] = bmin[0] + wid-1; bmax[1] = bmin[1] + wid-1; hilbert_box_vtx(2, sizeof(bitmask_t), iwbits, 1, bmin, bmax); sp->darr[sp->alen].hent = hilbert_c2i(2, iwbits, bmin); sp->darr[sp->alen].wid = wid; sp->darr[sp->alen].bsdf = val; sp->alen++; /* on to the next entry */ return 0; }
/* Callback to build cumulative distribution using SDtraverseTre() */
Callback to build cumulative distribution using SDtraverseTre()
[ "Callback", "to", "build", "cumulative", "distribution", "using", "SDtraverseTre", "()" ]
static int build_scaffold(float val, const double *cmin, double csiz, void *cptr) { SDdistScaffold *sp = (SDdistScaffold *)cptr; int wid = csiz*(double)iwmax + .5; double revcmin[2]; bitmask_t bmin[2], bmax[2]; if (sp->rev) { revcmin[0] = 1. - cmin[0] - csiz; revcmin[1] = 1. - cmin[1] - csiz; cmin = revcmin; } else { cmin += sp->nic; } if (wid < sp->wmin) sp->wmin = wid; if (wid > sp->wmax) sp->wmax = wid; if (sp->alen >= sp->nall) { struct outdir_s *ndarr; sp->nall += 1024; ndarr = (struct outdir_s *)realloc(sp->darr, sizeof(struct outdir_s)*sp->nall); if (ndarr == NULL) { sprintf(SDerrorDetail, "Cannot grow scaffold to %u entries", sp->nall); return -1; } sp->darr = ndarr; } bmin[0] = cmin[0]*(double)iwmax + .5; bmin[1] = cmin[1]*(double)iwmax + .5; bmax[0] = bmin[0] + wid-1; bmax[1] = bmin[1] + wid-1; hilbert_box_vtx(2, sizeof(bitmask_t), iwbits, 1, bmin, bmax); sp->darr[sp->alen].hent = hilbert_c2i(2, iwbits, bmin); sp->darr[sp->alen].wid = wid; sp->darr[sp->alen].bsdf = val; sp->alen++; return 0; }
[ "static", "int", "build_scaffold", "(", "float", "val", ",", "const", "double", "*", "cmin", ",", "double", "csiz", ",", "void", "*", "cptr", ")", "{", "SDdistScaffold", "*", "sp", "=", "(", "SDdistScaffold", "*", ")", "cptr", ";", "int", "wid", "=", "csiz", "*", "(", "double", ")", "iwmax", "+", ".5", ";", "double", "revcmin", "[", "2", "]", ";", "bitmask_t", "bmin", "[", "2", "]", ",", "bmax", "[", "2", "]", ";", "if", "(", "sp", "->", "rev", ")", "{", "revcmin", "[", "0", "]", "=", "1.", "-", "cmin", "[", "0", "]", "-", "csiz", ";", "revcmin", "[", "1", "]", "=", "1.", "-", "cmin", "[", "1", "]", "-", "csiz", ";", "cmin", "=", "revcmin", ";", "}", "else", "{", "cmin", "+=", "sp", "->", "nic", ";", "}", "if", "(", "wid", "<", "sp", "->", "wmin", ")", "sp", "->", "wmin", "=", "wid", ";", "if", "(", "wid", ">", "sp", "->", "wmax", ")", "sp", "->", "wmax", "=", "wid", ";", "if", "(", "sp", "->", "alen", ">=", "sp", "->", "nall", ")", "{", "struct", "outdir_s", "*", "ndarr", ";", "sp", "->", "nall", "+=", "1024", ";", "ndarr", "=", "(", "struct", "outdir_s", "*", ")", "realloc", "(", "sp", "->", "darr", ",", "sizeof", "(", "struct", "outdir_s", ")", "*", "sp", "->", "nall", ")", ";", "if", "(", "ndarr", "==", "NULL", ")", "{", "sprintf", "(", "SDerrorDetail", ",", "\"", "\"", ",", "sp", "->", "nall", ")", ";", "return", "-1", ";", "}", "sp", "->", "darr", "=", "ndarr", ";", "}", "bmin", "[", "0", "]", "=", "cmin", "[", "0", "]", "*", "(", "double", ")", "iwmax", "+", ".5", ";", "bmin", "[", "1", "]", "=", "cmin", "[", "1", "]", "*", "(", "double", ")", "iwmax", "+", ".5", ";", "bmax", "[", "0", "]", "=", "bmin", "[", "0", "]", "+", "wid", "-", "1", ";", "bmax", "[", "1", "]", "=", "bmin", "[", "1", "]", "+", "wid", "-", "1", ";", "hilbert_box_vtx", "(", "2", ",", "sizeof", "(", "bitmask_t", ")", ",", "iwbits", ",", "1", ",", "bmin", ",", "bmax", ")", ";", "sp", "->", "darr", "[", "sp", "->", "alen", "]", ".", "hent", "=", "hilbert_c2i", "(", "2", ",", "iwbits", ",", "bmin", ")", ";", "sp", "->", "darr", "[", "sp", "->", "alen", "]", ".", "wid", "=", "wid", ";", "sp", "->", "darr", "[", "sp", "->", "alen", "]", ".", "bsdf", "=", "val", ";", "sp", "->", "alen", "++", ";", "return", "0", ";", "}" ]
Callback to build cumulative distribution using SDtraverseTre()
[ "Callback", "to", "build", "cumulative", "distribution", "using", "SDtraverseTre", "()" ]
[ "/* need to reverse sense? */", "/* else skip to output coords */", "/* new minimum width? */", "/* new maximum? */", "/* need more space? */", "/* abort build */", "/* find Hilbert entry index */", "/* on to the next entry */" ]
[ { "param": "val", "type": "float" }, { "param": "cmin", "type": "double" }, { "param": "csiz", "type": "double" }, { "param": "cptr", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "val", "type": "float", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cmin", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "csiz", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cptr", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a6c95d46c7283f6706245c98f25a833141707292
kalyanam-FMTGA/ray-original
src/common/bsdf_t.c
[ "BSD-3-Clause-LBNL" ]
C
make_cdist
SDTreCDst
static SDTreCDst * make_cdist(const SDTre *sdt, const double *invec, int rev) { SDdistScaffold myScaffold; double pos[4]; int cmask; SDTreCDst *cd; struct outdir_s *sp; double scale, cursum; int i; /* initialize scaffold */ myScaffold.wmin = iwmax; myScaffold.wmax = 0; myScaffold.nic = sdt->st->ndim - 2; myScaffold.rev = rev; myScaffold.alen = 0; myScaffold.nall = 512; myScaffold.darr = (struct outdir_s *)malloc(sizeof(struct outdir_s) * myScaffold.nall); if (myScaffold.darr == NULL) return NULL; /* set up traversal */ cmask = (1<<myScaffold.nic) - 1; for (i = myScaffold.nic; i--; ) pos[i+2*rev] = invec[i]; cmask <<= 2*rev; /* grow the distribution */ if (SDtraverseTre(sdt->st, pos, cmask, &build_scaffold, &myScaffold) < 0) { free(myScaffold.darr); return NULL; } /* allocate result holder */ cd = (SDTreCDst *)malloc(sizeof(SDTreCDst) + sizeof(cd->carr[0])*myScaffold.alen); if (cd == NULL) { sprintf(SDerrorDetail, "Cannot allocate %u entry cumulative distribution", myScaffold.alen); free(myScaffold.darr); return NULL; } cd->isodist = (myScaffold.nic == 1); /* sort the distribution */ qsort(myScaffold.darr, cd->calen = myScaffold.alen, sizeof(struct outdir_s), &sscmp); /* record input range */ scale = myScaffold.wmin / (double)iwmax; for (i = myScaffold.nic; i--; ) { cd->clim[i][0] = floor(pos[i+2*rev]/scale) * scale; cd->clim[i][1] = cd->clim[i][0] + scale; } if (cd->isodist) { /* avoid issue in SDqueryTreProjSA() */ cd->clim[1][0] = cd->clim[0][0]; cd->clim[1][1] = cd->clim[0][1]; } cd->max_psa = myScaffold.wmax / (double)iwmax; cd->max_psa *= cd->max_psa * M_PI; if (rev) cd->sidef = (sdt->sidef==SD_BXMIT) ? SD_FXMIT : SD_BXMIT; else cd->sidef = sdt->sidef; cd->cTotal = 1e-20; /* compute directional total */ sp = myScaffold.darr; for (i = myScaffold.alen; i--; sp++) cd->cTotal += sp->bsdf * (double)sp->wid * sp->wid; cursum = .0; /* go back and get cumulative values */ scale = (double)cumlmax / cd->cTotal; sp = myScaffold.darr; for (i = 0; i < cd->calen; i++, sp++) { cd->carr[i].hndx = sp->hent; cd->carr[i].cuml = scale*cursum + .5; cursum += sp->bsdf * (double)sp->wid * sp->wid; } cd->carr[i].hndx = ~0; /* make final entry */ cd->carr[i].cuml = cumlmax; cd->cTotal *= M_PI/(double)iwmax/iwmax; /* all done, clean up and return */ free(myScaffold.darr); return cd; }
/* Create a new cumulative distribution for the given input direction */
Create a new cumulative distribution for the given input direction
[ "Create", "a", "new", "cumulative", "distribution", "for", "the", "given", "input", "direction" ]
static SDTreCDst * make_cdist(const SDTre *sdt, const double *invec, int rev) { SDdistScaffold myScaffold; double pos[4]; int cmask; SDTreCDst *cd; struct outdir_s *sp; double scale, cursum; int i; myScaffold.wmin = iwmax; myScaffold.wmax = 0; myScaffold.nic = sdt->st->ndim - 2; myScaffold.rev = rev; myScaffold.alen = 0; myScaffold.nall = 512; myScaffold.darr = (struct outdir_s *)malloc(sizeof(struct outdir_s) * myScaffold.nall); if (myScaffold.darr == NULL) return NULL; cmask = (1<<myScaffold.nic) - 1; for (i = myScaffold.nic; i--; ) pos[i+2*rev] = invec[i]; cmask <<= 2*rev; if (SDtraverseTre(sdt->st, pos, cmask, &build_scaffold, &myScaffold) < 0) { free(myScaffold.darr); return NULL; } cd = (SDTreCDst *)malloc(sizeof(SDTreCDst) + sizeof(cd->carr[0])*myScaffold.alen); if (cd == NULL) { sprintf(SDerrorDetail, "Cannot allocate %u entry cumulative distribution", myScaffold.alen); free(myScaffold.darr); return NULL; } cd->isodist = (myScaffold.nic == 1); qsort(myScaffold.darr, cd->calen = myScaffold.alen, sizeof(struct outdir_s), &sscmp); scale = myScaffold.wmin / (double)iwmax; for (i = myScaffold.nic; i--; ) { cd->clim[i][0] = floor(pos[i+2*rev]/scale) * scale; cd->clim[i][1] = cd->clim[i][0] + scale; } if (cd->isodist) { cd->clim[1][0] = cd->clim[0][0]; cd->clim[1][1] = cd->clim[0][1]; } cd->max_psa = myScaffold.wmax / (double)iwmax; cd->max_psa *= cd->max_psa * M_PI; if (rev) cd->sidef = (sdt->sidef==SD_BXMIT) ? SD_FXMIT : SD_BXMIT; else cd->sidef = sdt->sidef; cd->cTotal = 1e-20; sp = myScaffold.darr; for (i = myScaffold.alen; i--; sp++) cd->cTotal += sp->bsdf * (double)sp->wid * sp->wid; cursum = .0; scale = (double)cumlmax / cd->cTotal; sp = myScaffold.darr; for (i = 0; i < cd->calen; i++, sp++) { cd->carr[i].hndx = sp->hent; cd->carr[i].cuml = scale*cursum + .5; cursum += sp->bsdf * (double)sp->wid * sp->wid; } cd->carr[i].hndx = ~0; cd->carr[i].cuml = cumlmax; cd->cTotal *= M_PI/(double)iwmax/iwmax; free(myScaffold.darr); return cd; }
[ "static", "SDTreCDst", "*", "make_cdist", "(", "const", "SDTre", "*", "sdt", ",", "const", "double", "*", "invec", ",", "int", "rev", ")", "{", "SDdistScaffold", "myScaffold", ";", "double", "pos", "[", "4", "]", ";", "int", "cmask", ";", "SDTreCDst", "*", "cd", ";", "struct", "outdir_s", "*", "sp", ";", "double", "scale", ",", "cursum", ";", "int", "i", ";", "myScaffold", ".", "wmin", "=", "iwmax", ";", "myScaffold", ".", "wmax", "=", "0", ";", "myScaffold", ".", "nic", "=", "sdt", "->", "st", "->", "ndim", "-", "2", ";", "myScaffold", ".", "rev", "=", "rev", ";", "myScaffold", ".", "alen", "=", "0", ";", "myScaffold", ".", "nall", "=", "512", ";", "myScaffold", ".", "darr", "=", "(", "struct", "outdir_s", "*", ")", "malloc", "(", "sizeof", "(", "struct", "outdir_s", ")", "*", "myScaffold", ".", "nall", ")", ";", "if", "(", "myScaffold", ".", "darr", "==", "NULL", ")", "return", "NULL", ";", "cmask", "=", "(", "1", "<<", "myScaffold", ".", "nic", ")", "-", "1", ";", "for", "(", "i", "=", "myScaffold", ".", "nic", ";", "i", "--", ";", ")", "pos", "[", "i", "+", "2", "*", "rev", "]", "=", "invec", "[", "i", "]", ";", "cmask", "<<=", "2", "*", "rev", ";", "if", "(", "SDtraverseTre", "(", "sdt", "->", "st", ",", "pos", ",", "cmask", ",", "&", "build_scaffold", ",", "&", "myScaffold", ")", "<", "0", ")", "{", "free", "(", "myScaffold", ".", "darr", ")", ";", "return", "NULL", ";", "}", "cd", "=", "(", "SDTreCDst", "*", ")", "malloc", "(", "sizeof", "(", "SDTreCDst", ")", "+", "sizeof", "(", "cd", "->", "carr", "[", "0", "]", ")", "*", "myScaffold", ".", "alen", ")", ";", "if", "(", "cd", "==", "NULL", ")", "{", "sprintf", "(", "SDerrorDetail", ",", "\"", "\"", ",", "myScaffold", ".", "alen", ")", ";", "free", "(", "myScaffold", ".", "darr", ")", ";", "return", "NULL", ";", "}", "cd", "->", "isodist", "=", "(", "myScaffold", ".", "nic", "==", "1", ")", ";", "qsort", "(", "myScaffold", ".", "darr", ",", "cd", "->", "calen", "=", "myScaffold", ".", "alen", ",", "sizeof", "(", "struct", "outdir_s", ")", ",", "&", "sscmp", ")", ";", "scale", "=", "myScaffold", ".", "wmin", "/", "(", "double", ")", "iwmax", ";", "for", "(", "i", "=", "myScaffold", ".", "nic", ";", "i", "--", ";", ")", "{", "cd", "->", "clim", "[", "i", "]", "[", "0", "]", "=", "floor", "(", "pos", "[", "i", "+", "2", "*", "rev", "]", "/", "scale", ")", "*", "scale", ";", "cd", "->", "clim", "[", "i", "]", "[", "1", "]", "=", "cd", "->", "clim", "[", "i", "]", "[", "0", "]", "+", "scale", ";", "}", "if", "(", "cd", "->", "isodist", ")", "{", "cd", "->", "clim", "[", "1", "]", "[", "0", "]", "=", "cd", "->", "clim", "[", "0", "]", "[", "0", "]", ";", "cd", "->", "clim", "[", "1", "]", "[", "1", "]", "=", "cd", "->", "clim", "[", "0", "]", "[", "1", "]", ";", "}", "cd", "->", "max_psa", "=", "myScaffold", ".", "wmax", "/", "(", "double", ")", "iwmax", ";", "cd", "->", "max_psa", "*=", "cd", "->", "max_psa", "*", "M_PI", ";", "if", "(", "rev", ")", "cd", "->", "sidef", "=", "(", "sdt", "->", "sidef", "==", "SD_BXMIT", ")", "?", "SD_FXMIT", ":", "SD_BXMIT", ";", "else", "cd", "->", "sidef", "=", "sdt", "->", "sidef", ";", "cd", "->", "cTotal", "=", "1e-20", ";", "sp", "=", "myScaffold", ".", "darr", ";", "for", "(", "i", "=", "myScaffold", ".", "alen", ";", "i", "--", ";", "sp", "++", ")", "cd", "->", "cTotal", "+=", "sp", "->", "bsdf", "*", "(", "double", ")", "sp", "->", "wid", "*", "sp", "->", "wid", ";", "cursum", "=", ".0", ";", "scale", "=", "(", "double", ")", "cumlmax", "/", "cd", "->", "cTotal", ";", "sp", "=", "myScaffold", ".", "darr", ";", "for", "(", "i", "=", "0", ";", "i", "<", "cd", "->", "calen", ";", "i", "++", ",", "sp", "++", ")", "{", "cd", "->", "carr", "[", "i", "]", ".", "hndx", "=", "sp", "->", "hent", ";", "cd", "->", "carr", "[", "i", "]", ".", "cuml", "=", "scale", "*", "cursum", "+", ".5", ";", "cursum", "+=", "sp", "->", "bsdf", "*", "(", "double", ")", "sp", "->", "wid", "*", "sp", "->", "wid", ";", "}", "cd", "->", "carr", "[", "i", "]", ".", "hndx", "=", "~", "0", ";", "cd", "->", "carr", "[", "i", "]", ".", "cuml", "=", "cumlmax", ";", "cd", "->", "cTotal", "*=", "M_PI", "/", "(", "double", ")", "iwmax", "/", "iwmax", ";", "free", "(", "myScaffold", ".", "darr", ")", ";", "return", "cd", ";", "}" ]
Create a new cumulative distribution for the given input direction
[ "Create", "a", "new", "cumulative", "distribution", "for", "the", "given", "input", "direction" ]
[ "/* initialize scaffold */", "/* set up traversal */", "/* grow the distribution */", "/* allocate result holder */", "/* sort the distribution */", "/* record input range */", "/* avoid issue in SDqueryTreProjSA() */", "/* compute directional total */", "/* go back and get cumulative values */", "/* make final entry */", "/* all done, clean up and return */" ]
[ { "param": "sdt", "type": "SDTre" }, { "param": "invec", "type": "double" }, { "param": "rev", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sdt", "type": "SDTre", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "invec", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "rev", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a6c95d46c7283f6706245c98f25a833141707292
kalyanam-FMTGA/ray-original
src/common/bsdf_t.c
[ "BSD-3-Clause-LBNL" ]
C
SDgetTreCDist
SDCDst
const SDCDst * SDgetTreCDist(const FVECT inVec, SDComponent *sdc) { const SDTre *sdt; double inCoord[2]; int i; int mode; SDTreCDst *cd, *cdlast; /* check arguments */ if ((inVec == NULL) | (sdc == NULL) || (sdt = (SDTre *)sdc->dist) == NULL) return NULL; switch (mode = sdt->sidef) { /* check direction */ case SD_FREFL: if (inVec[2] < 0) return NULL; break; case SD_BREFL: if (inVec[2] > 0) return NULL; break; case SD_FXMIT: if (inVec[2] < 0) mode = SD_BXMIT; break; case SD_BXMIT: if (inVec[2] > 0) mode = SD_FXMIT; break; default: return NULL; } if (sdt->st->ndim == 3) { /* isotropic BSDF? */ if (mode != sdt->sidef) /* XXX unhandled reciprocity */ return &SDemptyCD; inCoord[0] = .5 - .5*sqrt(inVec[0]*inVec[0] + inVec[1]*inVec[1]); } else if (sdt->st->ndim == 4) { if (mode != sdt->sidef) /* use reciprocity? */ SDdisk2square(inCoord, inVec[0], inVec[1]); else SDdisk2square(inCoord, -inVec[0], -inVec[1]); } else return NULL; /* should be internal error */ /* quantize to avoid f.p. errors */ for (i = sdt->st->ndim - 2; i--; ) inCoord[i] = floor(inCoord[i]/quantum)*quantum + .5*quantum; cdlast = NULL; /* check for direction in cache list */ for (cd = (SDTreCDst *)sdc->cdList; cd != NULL; cdlast = cd, cd = cd->next) { if (cd->sidef != mode) continue; for (i = sdt->st->ndim - 2; i--; ) if ((cd->clim[i][0] > inCoord[i]) | (inCoord[i] >= cd->clim[i][1])) break; if (i < 0) break; /* means we have a match */ } if (cd == NULL) /* need to create new entry? */ cdlast = cd = make_cdist(sdt, inCoord, mode != sdt->sidef); if (cdlast != NULL) { /* move entry to head of cache list */ cdlast->next = cd->next; cd->next = (SDTreCDst *)sdc->cdList; sdc->cdList = (SDCDst *)cd; } return (SDCDst *)cd; /* ready to go */ }
/* Find or allocate a cumulative distribution for the given incoming vector */
Find or allocate a cumulative distribution for the given incoming vector
[ "Find", "or", "allocate", "a", "cumulative", "distribution", "for", "the", "given", "incoming", "vector" ]
const SDCDst * SDgetTreCDist(const FVECT inVec, SDComponent *sdc) { const SDTre *sdt; double inCoord[2]; int i; int mode; SDTreCDst *cd, *cdlast; if ((inVec == NULL) | (sdc == NULL) || (sdt = (SDTre *)sdc->dist) == NULL) return NULL; switch (mode = sdt->sidef) { case SD_FREFL: if (inVec[2] < 0) return NULL; break; case SD_BREFL: if (inVec[2] > 0) return NULL; break; case SD_FXMIT: if (inVec[2] < 0) mode = SD_BXMIT; break; case SD_BXMIT: if (inVec[2] > 0) mode = SD_FXMIT; break; default: return NULL; } if (sdt->st->ndim == 3) { if (mode != sdt->sidef) return &SDemptyCD; inCoord[0] = .5 - .5*sqrt(inVec[0]*inVec[0] + inVec[1]*inVec[1]); } else if (sdt->st->ndim == 4) { if (mode != sdt->sidef) SDdisk2square(inCoord, inVec[0], inVec[1]); else SDdisk2square(inCoord, -inVec[0], -inVec[1]); } else return NULL; for (i = sdt->st->ndim - 2; i--; ) inCoord[i] = floor(inCoord[i]/quantum)*quantum + .5*quantum; cdlast = NULL; for (cd = (SDTreCDst *)sdc->cdList; cd != NULL; cdlast = cd, cd = cd->next) { if (cd->sidef != mode) continue; for (i = sdt->st->ndim - 2; i--; ) if ((cd->clim[i][0] > inCoord[i]) | (inCoord[i] >= cd->clim[i][1])) break; if (i < 0) break; } if (cd == NULL) cdlast = cd = make_cdist(sdt, inCoord, mode != sdt->sidef); if (cdlast != NULL) { cdlast->next = cd->next; cd->next = (SDTreCDst *)sdc->cdList; sdc->cdList = (SDCDst *)cd; } return (SDCDst *)cd; }
[ "const", "SDCDst", "*", "SDgetTreCDist", "(", "const", "FVECT", "inVec", ",", "SDComponent", "*", "sdc", ")", "{", "const", "SDTre", "*", "sdt", ";", "double", "inCoord", "[", "2", "]", ";", "int", "i", ";", "int", "mode", ";", "SDTreCDst", "*", "cd", ",", "*", "cdlast", ";", "if", "(", "(", "inVec", "==", "NULL", ")", "|", "(", "sdc", "==", "NULL", ")", "||", "(", "sdt", "=", "(", "SDTre", "*", ")", "sdc", "->", "dist", ")", "==", "NULL", ")", "return", "NULL", ";", "switch", "(", "mode", "=", "sdt", "->", "sidef", ")", "{", "case", "SD_FREFL", ":", "if", "(", "inVec", "[", "2", "]", "<", "0", ")", "return", "NULL", ";", "break", ";", "case", "SD_BREFL", ":", "if", "(", "inVec", "[", "2", "]", ">", "0", ")", "return", "NULL", ";", "break", ";", "case", "SD_FXMIT", ":", "if", "(", "inVec", "[", "2", "]", "<", "0", ")", "mode", "=", "SD_BXMIT", ";", "break", ";", "case", "SD_BXMIT", ":", "if", "(", "inVec", "[", "2", "]", ">", "0", ")", "mode", "=", "SD_FXMIT", ";", "break", ";", "default", ":", "return", "NULL", ";", "}", "if", "(", "sdt", "->", "st", "->", "ndim", "==", "3", ")", "{", "if", "(", "mode", "!=", "sdt", "->", "sidef", ")", "return", "&", "SDemptyCD", ";", "inCoord", "[", "0", "]", "=", ".5", "-", ".5", "*", "sqrt", "(", "inVec", "[", "0", "]", "*", "inVec", "[", "0", "]", "+", "inVec", "[", "1", "]", "*", "inVec", "[", "1", "]", ")", ";", "}", "else", "if", "(", "sdt", "->", "st", "->", "ndim", "==", "4", ")", "{", "if", "(", "mode", "!=", "sdt", "->", "sidef", ")", "SDdisk2square", "(", "inCoord", ",", "inVec", "[", "0", "]", ",", "inVec", "[", "1", "]", ")", ";", "else", "SDdisk2square", "(", "inCoord", ",", "-", "inVec", "[", "0", "]", ",", "-", "inVec", "[", "1", "]", ")", ";", "}", "else", "return", "NULL", ";", "for", "(", "i", "=", "sdt", "->", "st", "->", "ndim", "-", "2", ";", "i", "--", ";", ")", "inCoord", "[", "i", "]", "=", "floor", "(", "inCoord", "[", "i", "]", "/", "quantum", ")", "*", "quantum", "+", ".5", "*", "quantum", ";", "cdlast", "=", "NULL", ";", "for", "(", "cd", "=", "(", "SDTreCDst", "*", ")", "sdc", "->", "cdList", ";", "cd", "!=", "NULL", ";", "cdlast", "=", "cd", ",", "cd", "=", "cd", "->", "next", ")", "{", "if", "(", "cd", "->", "sidef", "!=", "mode", ")", "continue", ";", "for", "(", "i", "=", "sdt", "->", "st", "->", "ndim", "-", "2", ";", "i", "--", ";", ")", "if", "(", "(", "cd", "->", "clim", "[", "i", "]", "[", "0", "]", ">", "inCoord", "[", "i", "]", ")", "|", "(", "inCoord", "[", "i", "]", ">=", "cd", "->", "clim", "[", "i", "]", "[", "1", "]", ")", ")", "break", ";", "if", "(", "i", "<", "0", ")", "break", ";", "}", "if", "(", "cd", "==", "NULL", ")", "cdlast", "=", "cd", "=", "make_cdist", "(", "sdt", ",", "inCoord", ",", "mode", "!=", "sdt", "->", "sidef", ")", ";", "if", "(", "cdlast", "!=", "NULL", ")", "{", "cdlast", "->", "next", "=", "cd", "->", "next", ";", "cd", "->", "next", "=", "(", "SDTreCDst", "*", ")", "sdc", "->", "cdList", ";", "sdc", "->", "cdList", "=", "(", "SDCDst", "*", ")", "cd", ";", "}", "return", "(", "SDCDst", "*", ")", "cd", ";", "}" ]
Find or allocate a cumulative distribution for the given incoming vector
[ "Find", "or", "allocate", "a", "cumulative", "distribution", "for", "the", "given", "incoming", "vector" ]
[ "/* check arguments */", "/* check direction */", "/* isotropic BSDF? */", "/* XXX unhandled reciprocity */", "/* use reciprocity? */", "/* should be internal error */", "/* quantize to avoid f.p. errors */", "/* check for direction in cache list */", "/* means we have a match */", "/* need to create new entry? */", "/* move entry to head of cache list */", "/* ready to go */" ]
[ { "param": "inVec", "type": "FVECT" }, { "param": "sdc", "type": "SDComponent" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "inVec", "type": "FVECT", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "sdc", "type": "SDComponent", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a6c95d46c7283f6706245c98f25a833141707292
kalyanam-FMTGA/ray-original
src/common/bsdf_t.c
[ "BSD-3-Clause-LBNL" ]
C
SDqueryTreProjSA
SDError
static SDError SDqueryTreProjSA(double *psa, const FVECT v1, const RREAL *v2, int qflags, SDComponent *sdc) { double myPSA[2]; /* check arguments */ if ((psa == NULL) | (v1 == NULL) | (sdc == NULL) || sdc->dist == NULL) return SDEargument; /* get projected solid angle(s) */ if (v2 != NULL) { const SDTre *sdt = (SDTre *)sdc->dist; double hcube[SD_MAXDIM]; if (SDqueryTre(sdt, v1, v2, hcube) < 0) { strcpy(SDerrorDetail, "Bad call to SDqueryTreProjSA"); return SDEinternal; } myPSA[0] = hcube[sdt->st->ndim]; myPSA[1] = myPSA[0] *= myPSA[0] * M_PI; } else { const SDTreCDst *cd = (const SDTreCDst *)SDgetTreCDist(v1, sdc); if (cd == NULL) return SDEmemory; myPSA[0] = M_PI * (cd->clim[0][1] - cd->clim[0][0]) * (cd->clim[1][1] - cd->clim[1][0]); myPSA[1] = cd->max_psa; } switch (qflags) { /* record based on flag settings */ case SDqueryVal: *psa = myPSA[0]; break; case SDqueryMax: if (myPSA[1] > *psa) *psa = myPSA[1]; break; case SDqueryMin+SDqueryMax: if (myPSA[1] > psa[1]) psa[1] = myPSA[1]; /* fall through */ case SDqueryMin: if (myPSA[0] < psa[0]) psa[0] = myPSA[0]; break; } return SDEnone; }
/* Query solid angle for vector(s) */
Query solid angle for vector(s)
[ "Query", "solid", "angle", "for", "vector", "(", "s", ")" ]
static SDError SDqueryTreProjSA(double *psa, const FVECT v1, const RREAL *v2, int qflags, SDComponent *sdc) { double myPSA[2]; if ((psa == NULL) | (v1 == NULL) | (sdc == NULL) || sdc->dist == NULL) return SDEargument; if (v2 != NULL) { const SDTre *sdt = (SDTre *)sdc->dist; double hcube[SD_MAXDIM]; if (SDqueryTre(sdt, v1, v2, hcube) < 0) { strcpy(SDerrorDetail, "Bad call to SDqueryTreProjSA"); return SDEinternal; } myPSA[0] = hcube[sdt->st->ndim]; myPSA[1] = myPSA[0] *= myPSA[0] * M_PI; } else { const SDTreCDst *cd = (const SDTreCDst *)SDgetTreCDist(v1, sdc); if (cd == NULL) return SDEmemory; myPSA[0] = M_PI * (cd->clim[0][1] - cd->clim[0][0]) * (cd->clim[1][1] - cd->clim[1][0]); myPSA[1] = cd->max_psa; } switch (qflags) { case SDqueryVal: *psa = myPSA[0]; break; case SDqueryMax: if (myPSA[1] > *psa) *psa = myPSA[1]; break; case SDqueryMin+SDqueryMax: if (myPSA[1] > psa[1]) psa[1] = myPSA[1]; case SDqueryMin: if (myPSA[0] < psa[0]) psa[0] = myPSA[0]; break; } return SDEnone; }
[ "static", "SDError", "SDqueryTreProjSA", "(", "double", "*", "psa", ",", "const", "FVECT", "v1", ",", "const", "RREAL", "*", "v2", ",", "int", "qflags", ",", "SDComponent", "*", "sdc", ")", "{", "double", "myPSA", "[", "2", "]", ";", "if", "(", "(", "psa", "==", "NULL", ")", "|", "(", "v1", "==", "NULL", ")", "|", "(", "sdc", "==", "NULL", ")", "||", "sdc", "->", "dist", "==", "NULL", ")", "return", "SDEargument", ";", "if", "(", "v2", "!=", "NULL", ")", "{", "const", "SDTre", "*", "sdt", "=", "(", "SDTre", "*", ")", "sdc", "->", "dist", ";", "double", "hcube", "[", "SD_MAXDIM", "]", ";", "if", "(", "SDqueryTre", "(", "sdt", ",", "v1", ",", "v2", ",", "hcube", ")", "<", "0", ")", "{", "strcpy", "(", "SDerrorDetail", ",", "\"", "\"", ")", ";", "return", "SDEinternal", ";", "}", "myPSA", "[", "0", "]", "=", "hcube", "[", "sdt", "->", "st", "->", "ndim", "]", ";", "myPSA", "[", "1", "]", "=", "myPSA", "[", "0", "]", "*=", "myPSA", "[", "0", "]", "*", "M_PI", ";", "}", "else", "{", "const", "SDTreCDst", "*", "cd", "=", "(", "const", "SDTreCDst", "*", ")", "SDgetTreCDist", "(", "v1", ",", "sdc", ")", ";", "if", "(", "cd", "==", "NULL", ")", "return", "SDEmemory", ";", "myPSA", "[", "0", "]", "=", "M_PI", "*", "(", "cd", "->", "clim", "[", "0", "]", "[", "1", "]", "-", "cd", "->", "clim", "[", "0", "]", "[", "0", "]", ")", "*", "(", "cd", "->", "clim", "[", "1", "]", "[", "1", "]", "-", "cd", "->", "clim", "[", "1", "]", "[", "0", "]", ")", ";", "myPSA", "[", "1", "]", "=", "cd", "->", "max_psa", ";", "}", "switch", "(", "qflags", ")", "{", "case", "SDqueryVal", ":", "*", "psa", "=", "myPSA", "[", "0", "]", ";", "break", ";", "case", "SDqueryMax", ":", "if", "(", "myPSA", "[", "1", "]", ">", "*", "psa", ")", "*", "psa", "=", "myPSA", "[", "1", "]", ";", "break", ";", "case", "SDqueryMin", "+", "SDqueryMax", ":", "if", "(", "myPSA", "[", "1", "]", ">", "psa", "[", "1", "]", ")", "psa", "[", "1", "]", "=", "myPSA", "[", "1", "]", ";", "case", "SDqueryMin", ":", "if", "(", "myPSA", "[", "0", "]", "<", "psa", "[", "0", "]", ")", "psa", "[", "0", "]", "=", "myPSA", "[", "0", "]", ";", "break", ";", "}", "return", "SDEnone", ";", "}" ]
Query solid angle for vector(s)
[ "Query", "solid", "angle", "for", "vector", "(", "s", ")" ]
[ "/* check arguments */", "/* get projected solid angle(s) */", "/* record based on flag settings */", "/* fall through */" ]
[ { "param": "psa", "type": "double" }, { "param": "v1", "type": "FVECT" }, { "param": "v2", "type": "RREAL" }, { "param": "qflags", "type": "int" }, { "param": "sdc", "type": "SDComponent" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "psa", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "v1", "type": "FVECT", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "v2", "type": "RREAL", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "qflags", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "sdc", "type": "SDComponent", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a6c95d46c7283f6706245c98f25a833141707292
kalyanam-FMTGA/ray-original
src/common/bsdf_t.c
[ "BSD-3-Clause-LBNL" ]
C
load_values
int
static int load_values(char **spp, float *va, int n) { float *v = va; char *svnext; while (n-- > 0 && (svnext = fskip(*spp)) != NULL) { *v++ = atof(*spp); *spp = svnext; eat_token(spp, ','); } return v - va; }
/* Load an array of real numbers, returning total */
Load an array of real numbers, returning total
[ "Load", "an", "array", "of", "real", "numbers", "returning", "total" ]
static int load_values(char **spp, float *va, int n) { float *v = va; char *svnext; while (n-- > 0 && (svnext = fskip(*spp)) != NULL) { *v++ = atof(*spp); *spp = svnext; eat_token(spp, ','); } return v - va; }
[ "static", "int", "load_values", "(", "char", "*", "*", "spp", ",", "float", "*", "va", ",", "int", "n", ")", "{", "float", "*", "v", "=", "va", ";", "char", "*", "svnext", ";", "while", "(", "n", "--", ">", "0", "&&", "(", "svnext", "=", "fskip", "(", "*", "spp", ")", ")", "!=", "NULL", ")", "{", "*", "v", "++", "=", "atof", "(", "*", "spp", ")", ";", "*", "spp", "=", "svnext", ";", "eat_token", "(", "spp", ",", "'", "'", ")", ";", "}", "return", "v", "-", "va", ";", "}" ]
Load an array of real numbers, returning total
[ "Load", "an", "array", "of", "real", "numbers", "returning", "total" ]
[]
[ { "param": "spp", "type": "char" }, { "param": "va", "type": "float" }, { "param": "n", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "spp", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "va", "type": "float", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "n", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a6c95d46c7283f6706245c98f25a833141707292
kalyanam-FMTGA/ray-original
src/common/bsdf_t.c
[ "BSD-3-Clause-LBNL" ]
C
load_bsdf_data
SDError
static SDError load_bsdf_data(SDData *sd, ezxml_t wdb, int ndim) { SDSpectralDF *df; SDTre *sdt; char *sdata; /* allocate BSDF component */ sdata = ezxml_txt(ezxml_child(wdb, "WavelengthDataDirection")); if (!sdata) return SDEnone; /* * Remember that front and back are reversed from WINDOW 6 orientations */ if (!strcasecmp(sdata, "Transmission Front")) { if (sd->tb != NULL) SDfreeSpectralDF(sd->tb); if ((sd->tb = SDnewSpectralDF(1)) == NULL) return SDEmemory; df = sd->tb; } else if (!strcasecmp(sdata, "Transmission Back")) { if (sd->tf != NULL) SDfreeSpectralDF(sd->tf); if ((sd->tf = SDnewSpectralDF(1)) == NULL) return SDEmemory; df = sd->tf; } else if (!strcasecmp(sdata, "Reflection Front")) { if (sd->rb != NULL) SDfreeSpectralDF(sd->rb); if ((sd->rb = SDnewSpectralDF(1)) == NULL) return SDEmemory; df = sd->rb; } else if (!strcasecmp(sdata, "Reflection Back")) { if (sd->rf != NULL) SDfreeSpectralDF(sd->rf); if ((sd->rf = SDnewSpectralDF(1)) == NULL) return SDEmemory; df = sd->rf; } else return SDEnone; /* XXX should also check "ScatteringDataType" for consistency? */ /* get angle bases */ sdata = ezxml_txt(ezxml_child(wdb,"AngleBasis")); if (!sdata || strcasecmp(sdata, "LBNL/Shirley-Chiu")) { sprintf(SDerrorDetail, "%s angle basis for BSDF '%s'", !sdata ? "Missing" : "Unsupported", sd->name); return !sdata ? SDEformat : SDEsupport; } /* allocate BSDF tree */ sdt = (SDTre *)malloc(sizeof(SDTre)); if (sdt == NULL) return SDEmemory; if (df == sd->rf) sdt->sidef = SD_FREFL; else if (df == sd->rb) sdt->sidef = SD_BREFL; else if (df == sd->tf) sdt->sidef = SD_FXMIT; else /* df == sd->tb */ sdt->sidef = SD_BXMIT; sdt->st = NULL; df->comp[0].cspec[0] = c_dfcolor; /* XXX monochrome for now */ df->comp[0].dist = sdt; df->comp[0].func = &SDhandleTre; /* read BSDF data */ sdata = ezxml_txt(ezxml_child(wdb, "ScatteringData")); if (!sdata || !next_token(&sdata)) { sprintf(SDerrorDetail, "Missing BSDF ScatteringData in '%s'", sd->name); return SDEformat; } sdt->st = load_tree_data(&sdata, ndim); if (sdt->st == NULL) return SDEformat; if (next_token(&sdata)) { /* check for unconsumed characters */ sprintf(SDerrorDetail, "Extra characters at end of ScatteringData in '%s'", sd->name); return SDEformat; } /* flatten branches where possible */ sdt->st = SDsimplifyTre(sdt->st); if (sdt->st == NULL) return SDEinternal; return get_extrema(df); /* compute global quantities */ }
/* Load BSDF distribution for this wavelength */
Load BSDF distribution for this wavelength
[ "Load", "BSDF", "distribution", "for", "this", "wavelength" ]
static SDError load_bsdf_data(SDData *sd, ezxml_t wdb, int ndim) { SDSpectralDF *df; SDTre *sdt; char *sdata; sdata = ezxml_txt(ezxml_child(wdb, "WavelengthDataDirection")); if (!sdata) return SDEnone; if (!strcasecmp(sdata, "Transmission Front")) { if (sd->tb != NULL) SDfreeSpectralDF(sd->tb); if ((sd->tb = SDnewSpectralDF(1)) == NULL) return SDEmemory; df = sd->tb; } else if (!strcasecmp(sdata, "Transmission Back")) { if (sd->tf != NULL) SDfreeSpectralDF(sd->tf); if ((sd->tf = SDnewSpectralDF(1)) == NULL) return SDEmemory; df = sd->tf; } else if (!strcasecmp(sdata, "Reflection Front")) { if (sd->rb != NULL) SDfreeSpectralDF(sd->rb); if ((sd->rb = SDnewSpectralDF(1)) == NULL) return SDEmemory; df = sd->rb; } else if (!strcasecmp(sdata, "Reflection Back")) { if (sd->rf != NULL) SDfreeSpectralDF(sd->rf); if ((sd->rf = SDnewSpectralDF(1)) == NULL) return SDEmemory; df = sd->rf; } else return SDEnone; sdata = ezxml_txt(ezxml_child(wdb,"AngleBasis")); if (!sdata || strcasecmp(sdata, "LBNL/Shirley-Chiu")) { sprintf(SDerrorDetail, "%s angle basis for BSDF '%s'", !sdata ? "Missing" : "Unsupported", sd->name); return !sdata ? SDEformat : SDEsupport; } sdt = (SDTre *)malloc(sizeof(SDTre)); if (sdt == NULL) return SDEmemory; if (df == sd->rf) sdt->sidef = SD_FREFL; else if (df == sd->rb) sdt->sidef = SD_BREFL; else if (df == sd->tf) sdt->sidef = SD_FXMIT; else sdt->sidef = SD_BXMIT; sdt->st = NULL; df->comp[0].cspec[0] = c_dfcolor; df->comp[0].dist = sdt; df->comp[0].func = &SDhandleTre; sdata = ezxml_txt(ezxml_child(wdb, "ScatteringData")); if (!sdata || !next_token(&sdata)) { sprintf(SDerrorDetail, "Missing BSDF ScatteringData in '%s'", sd->name); return SDEformat; } sdt->st = load_tree_data(&sdata, ndim); if (sdt->st == NULL) return SDEformat; if (next_token(&sdata)) { sprintf(SDerrorDetail, "Extra characters at end of ScatteringData in '%s'", sd->name); return SDEformat; } sdt->st = SDsimplifyTre(sdt->st); if (sdt->st == NULL) return SDEinternal; return get_extrema(df); }
[ "static", "SDError", "load_bsdf_data", "(", "SDData", "*", "sd", ",", "ezxml_t", "wdb", ",", "int", "ndim", ")", "{", "SDSpectralDF", "*", "df", ";", "SDTre", "*", "sdt", ";", "char", "*", "sdata", ";", "sdata", "=", "ezxml_txt", "(", "ezxml_child", "(", "wdb", ",", "\"", "\"", ")", ")", ";", "if", "(", "!", "sdata", ")", "return", "SDEnone", ";", "if", "(", "!", "strcasecmp", "(", "sdata", ",", "\"", "\"", ")", ")", "{", "if", "(", "sd", "->", "tb", "!=", "NULL", ")", "SDfreeSpectralDF", "(", "sd", "->", "tb", ")", ";", "if", "(", "(", "sd", "->", "tb", "=", "SDnewSpectralDF", "(", "1", ")", ")", "==", "NULL", ")", "return", "SDEmemory", ";", "df", "=", "sd", "->", "tb", ";", "}", "else", "if", "(", "!", "strcasecmp", "(", "sdata", ",", "\"", "\"", ")", ")", "{", "if", "(", "sd", "->", "tf", "!=", "NULL", ")", "SDfreeSpectralDF", "(", "sd", "->", "tf", ")", ";", "if", "(", "(", "sd", "->", "tf", "=", "SDnewSpectralDF", "(", "1", ")", ")", "==", "NULL", ")", "return", "SDEmemory", ";", "df", "=", "sd", "->", "tf", ";", "}", "else", "if", "(", "!", "strcasecmp", "(", "sdata", ",", "\"", "\"", ")", ")", "{", "if", "(", "sd", "->", "rb", "!=", "NULL", ")", "SDfreeSpectralDF", "(", "sd", "->", "rb", ")", ";", "if", "(", "(", "sd", "->", "rb", "=", "SDnewSpectralDF", "(", "1", ")", ")", "==", "NULL", ")", "return", "SDEmemory", ";", "df", "=", "sd", "->", "rb", ";", "}", "else", "if", "(", "!", "strcasecmp", "(", "sdata", ",", "\"", "\"", ")", ")", "{", "if", "(", "sd", "->", "rf", "!=", "NULL", ")", "SDfreeSpectralDF", "(", "sd", "->", "rf", ")", ";", "if", "(", "(", "sd", "->", "rf", "=", "SDnewSpectralDF", "(", "1", ")", ")", "==", "NULL", ")", "return", "SDEmemory", ";", "df", "=", "sd", "->", "rf", ";", "}", "else", "return", "SDEnone", ";", "sdata", "=", "ezxml_txt", "(", "ezxml_child", "(", "wdb", ",", "\"", "\"", ")", ")", ";", "if", "(", "!", "sdata", "||", "strcasecmp", "(", "sdata", ",", "\"", "\"", ")", ")", "{", "sprintf", "(", "SDerrorDetail", ",", "\"", "\"", ",", "!", "sdata", "?", "\"", "\"", ":", "\"", "\"", ",", "sd", "->", "name", ")", ";", "return", "!", "sdata", "?", "SDEformat", ":", "SDEsupport", ";", "}", "sdt", "=", "(", "SDTre", "*", ")", "malloc", "(", "sizeof", "(", "SDTre", ")", ")", ";", "if", "(", "sdt", "==", "NULL", ")", "return", "SDEmemory", ";", "if", "(", "df", "==", "sd", "->", "rf", ")", "sdt", "->", "sidef", "=", "SD_FREFL", ";", "else", "if", "(", "df", "==", "sd", "->", "rb", ")", "sdt", "->", "sidef", "=", "SD_BREFL", ";", "else", "if", "(", "df", "==", "sd", "->", "tf", ")", "sdt", "->", "sidef", "=", "SD_FXMIT", ";", "else", "sdt", "->", "sidef", "=", "SD_BXMIT", ";", "sdt", "->", "st", "=", "NULL", ";", "df", "->", "comp", "[", "0", "]", ".", "cspec", "[", "0", "]", "=", "c_dfcolor", ";", "df", "->", "comp", "[", "0", "]", ".", "dist", "=", "sdt", ";", "df", "->", "comp", "[", "0", "]", ".", "func", "=", "&", "SDhandleTre", ";", "sdata", "=", "ezxml_txt", "(", "ezxml_child", "(", "wdb", ",", "\"", "\"", ")", ")", ";", "if", "(", "!", "sdata", "||", "!", "next_token", "(", "&", "sdata", ")", ")", "{", "sprintf", "(", "SDerrorDetail", ",", "\"", "\"", ",", "sd", "->", "name", ")", ";", "return", "SDEformat", ";", "}", "sdt", "->", "st", "=", "load_tree_data", "(", "&", "sdata", ",", "ndim", ")", ";", "if", "(", "sdt", "->", "st", "==", "NULL", ")", "return", "SDEformat", ";", "if", "(", "next_token", "(", "&", "sdata", ")", ")", "{", "sprintf", "(", "SDerrorDetail", ",", "\"", "\"", ",", "sd", "->", "name", ")", ";", "return", "SDEformat", ";", "}", "sdt", "->", "st", "=", "SDsimplifyTre", "(", "sdt", "->", "st", ")", ";", "if", "(", "sdt", "->", "st", "==", "NULL", ")", "return", "SDEinternal", ";", "return", "get_extrema", "(", "df", ")", ";", "}" ]
Load BSDF distribution for this wavelength
[ "Load", "BSDF", "distribution", "for", "this", "wavelength" ]
[ "/* allocate BSDF component */", "/*\n\t * Remember that front and back are reversed from WINDOW 6 orientations\n\t */", "/* XXX should also check \"ScatteringDataType\" for consistency? */", "/* get angle bases */", "/* allocate BSDF tree */", "/* df == sd->tb */", "/* XXX monochrome for now */", "/* read BSDF data */", "/* check for unconsumed characters */", "/* flatten branches where possible */", "/* compute global quantities */" ]
[ { "param": "sd", "type": "SDData" }, { "param": "wdb", "type": "ezxml_t" }, { "param": "ndim", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sd", "type": "SDData", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "wdb", "type": "ezxml_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "ndim", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a6c95d46c7283f6706245c98f25a833141707292
kalyanam-FMTGA/ray-original
src/common/bsdf_t.c
[ "BSD-3-Clause-LBNL" ]
C
extract_diffuse
void
static void extract_diffuse(SDValue *dv, SDSpectralDF *df) { int n; if (df == NULL || df->ncomp <= 0) { dv->spec = c_dfcolor; dv->cieY = .0; return; } dv->spec = df->comp[0].cspec[0]; dv->cieY = subtract_min((*(SDTre *)df->comp[0].dist).st); /* in case of multiple components */ for (n = df->ncomp; --n; ) { double ymin = subtract_min((*(SDTre *)df->comp[n].dist).st); c_cmix(&dv->spec, dv->cieY, &dv->spec, ymin, &df->comp[n].cspec[0]); dv->cieY += ymin; } df->maxHemi -= dv->cieY; /* adjust maximum hemispherical */ /* make sure everything is set */ c_ccvt(&dv->spec, C_CSXY+C_CSSPEC); }
/* Extract and separate diffuse portion of BSDF */
Extract and separate diffuse portion of BSDF
[ "Extract", "and", "separate", "diffuse", "portion", "of", "BSDF" ]
static void extract_diffuse(SDValue *dv, SDSpectralDF *df) { int n; if (df == NULL || df->ncomp <= 0) { dv->spec = c_dfcolor; dv->cieY = .0; return; } dv->spec = df->comp[0].cspec[0]; dv->cieY = subtract_min((*(SDTre *)df->comp[0].dist).st); for (n = df->ncomp; --n; ) { double ymin = subtract_min((*(SDTre *)df->comp[n].dist).st); c_cmix(&dv->spec, dv->cieY, &dv->spec, ymin, &df->comp[n].cspec[0]); dv->cieY += ymin; } df->maxHemi -= dv->cieY; c_ccvt(&dv->spec, C_CSXY+C_CSSPEC); }
[ "static", "void", "extract_diffuse", "(", "SDValue", "*", "dv", ",", "SDSpectralDF", "*", "df", ")", "{", "int", "n", ";", "if", "(", "df", "==", "NULL", "||", "df", "->", "ncomp", "<=", "0", ")", "{", "dv", "->", "spec", "=", "c_dfcolor", ";", "dv", "->", "cieY", "=", ".0", ";", "return", ";", "}", "dv", "->", "spec", "=", "df", "->", "comp", "[", "0", "]", ".", "cspec", "[", "0", "]", ";", "dv", "->", "cieY", "=", "subtract_min", "(", "(", "*", "(", "SDTre", "*", ")", "df", "->", "comp", "[", "0", "]", ".", "dist", ")", ".", "st", ")", ";", "for", "(", "n", "=", "df", "->", "ncomp", ";", "--", "n", ";", ")", "{", "double", "ymin", "=", "subtract_min", "(", "(", "*", "(", "SDTre", "*", ")", "df", "->", "comp", "[", "n", "]", ".", "dist", ")", ".", "st", ")", ";", "c_cmix", "(", "&", "dv", "->", "spec", ",", "dv", "->", "cieY", ",", "&", "dv", "->", "spec", ",", "ymin", ",", "&", "df", "->", "comp", "[", "n", "]", ".", "cspec", "[", "0", "]", ")", ";", "dv", "->", "cieY", "+=", "ymin", ";", "}", "df", "->", "maxHemi", "-=", "dv", "->", "cieY", ";", "c_ccvt", "(", "&", "dv", "->", "spec", ",", "C_CSXY", "+", "C_CSSPEC", ")", ";", "}" ]
Extract and separate diffuse portion of BSDF
[ "Extract", "and", "separate", "diffuse", "portion", "of", "BSDF" ]
[ "/* in case of multiple components */", "/* adjust maximum hemispherical */", "/* make sure everything is set */" ]
[ { "param": "dv", "type": "SDValue" }, { "param": "df", "type": "SDSpectralDF" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dv", "type": "SDValue", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "df", "type": "SDSpectralDF", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a6c95d46c7283f6706245c98f25a833141707292
kalyanam-FMTGA/ray-original
src/common/bsdf_t.c
[ "BSD-3-Clause-LBNL" ]
C
SDloadTre
SDError
SDError SDloadTre(SDData *sd, ezxml_t wtl) { SDError ec; ezxml_t wld, wdb; int rank; char *txt; /* basic checks and tensor rank */ txt = ezxml_txt(ezxml_child(ezxml_child(wtl, "DataDefinition"), "IncidentDataStructure")); if (txt == NULL || !*txt) { sprintf(SDerrorDetail, "BSDF \"%s\": missing IncidentDataStructure", sd->name); return SDEformat; } if (!strcasecmp(txt, "TensorTree3")) rank = 3; else if (!strcasecmp(txt, "TensorTree4")) rank = 4; else { sprintf(SDerrorDetail, "BSDF \"%s\": unsupported IncidentDataStructure", sd->name); return SDEsupport; } /* load BSDF components */ for (wld = ezxml_child(wtl, "WavelengthData"); wld != NULL; wld = wld->next) { if (strcasecmp(ezxml_txt(ezxml_child(wld,"Wavelength")), "Visible")) continue; /* just visible for now */ for (wdb = ezxml_child(wld, "WavelengthDataBlock"); wdb != NULL; wdb = wdb->next) if ((ec = load_bsdf_data(sd, wdb, rank)) != SDEnone) return ec; } /* separate diffuse components */ extract_diffuse(&sd->rLambFront, sd->rf); extract_diffuse(&sd->rLambBack, sd->rb); if (sd->tf != NULL) extract_diffuse(&sd->tLamb, sd->tf); if (sd->tb != NULL) extract_diffuse(&sd->tLamb, sd->tb); /* return success */ return SDEnone; }
/* Load a variable-resolution BSDF tree from an open XML file */
Load a variable-resolution BSDF tree from an open XML file
[ "Load", "a", "variable", "-", "resolution", "BSDF", "tree", "from", "an", "open", "XML", "file" ]
SDError SDloadTre(SDData *sd, ezxml_t wtl) { SDError ec; ezxml_t wld, wdb; int rank; char *txt; txt = ezxml_txt(ezxml_child(ezxml_child(wtl, "DataDefinition"), "IncidentDataStructure")); if (txt == NULL || !*txt) { sprintf(SDerrorDetail, "BSDF \"%s\": missing IncidentDataStructure", sd->name); return SDEformat; } if (!strcasecmp(txt, "TensorTree3")) rank = 3; else if (!strcasecmp(txt, "TensorTree4")) rank = 4; else { sprintf(SDerrorDetail, "BSDF \"%s\": unsupported IncidentDataStructure", sd->name); return SDEsupport; } for (wld = ezxml_child(wtl, "WavelengthData"); wld != NULL; wld = wld->next) { if (strcasecmp(ezxml_txt(ezxml_child(wld,"Wavelength")), "Visible")) continue; for (wdb = ezxml_child(wld, "WavelengthDataBlock"); wdb != NULL; wdb = wdb->next) if ((ec = load_bsdf_data(sd, wdb, rank)) != SDEnone) return ec; } extract_diffuse(&sd->rLambFront, sd->rf); extract_diffuse(&sd->rLambBack, sd->rb); if (sd->tf != NULL) extract_diffuse(&sd->tLamb, sd->tf); if (sd->tb != NULL) extract_diffuse(&sd->tLamb, sd->tb); return SDEnone; }
[ "SDError", "SDloadTre", "(", "SDData", "*", "sd", ",", "ezxml_t", "wtl", ")", "{", "SDError", "ec", ";", "ezxml_t", "wld", ",", "wdb", ";", "int", "rank", ";", "char", "*", "txt", ";", "txt", "=", "ezxml_txt", "(", "ezxml_child", "(", "ezxml_child", "(", "wtl", ",", "\"", "\"", ")", ",", "\"", "\"", ")", ")", ";", "if", "(", "txt", "==", "NULL", "||", "!", "*", "txt", ")", "{", "sprintf", "(", "SDerrorDetail", ",", "\"", "\\\"", "\\\"", "\"", ",", "sd", "->", "name", ")", ";", "return", "SDEformat", ";", "}", "if", "(", "!", "strcasecmp", "(", "txt", ",", "\"", "\"", ")", ")", "rank", "=", "3", ";", "else", "if", "(", "!", "strcasecmp", "(", "txt", ",", "\"", "\"", ")", ")", "rank", "=", "4", ";", "else", "{", "sprintf", "(", "SDerrorDetail", ",", "\"", "\\\"", "\\\"", "\"", ",", "sd", "->", "name", ")", ";", "return", "SDEsupport", ";", "}", "for", "(", "wld", "=", "ezxml_child", "(", "wtl", ",", "\"", "\"", ")", ";", "wld", "!=", "NULL", ";", "wld", "=", "wld", "->", "next", ")", "{", "if", "(", "strcasecmp", "(", "ezxml_txt", "(", "ezxml_child", "(", "wld", ",", "\"", "\"", ")", ")", ",", "\"", "\"", ")", ")", "continue", ";", "for", "(", "wdb", "=", "ezxml_child", "(", "wld", ",", "\"", "\"", ")", ";", "wdb", "!=", "NULL", ";", "wdb", "=", "wdb", "->", "next", ")", "if", "(", "(", "ec", "=", "load_bsdf_data", "(", "sd", ",", "wdb", ",", "rank", ")", ")", "!=", "SDEnone", ")", "return", "ec", ";", "}", "extract_diffuse", "(", "&", "sd", "->", "rLambFront", ",", "sd", "->", "rf", ")", ";", "extract_diffuse", "(", "&", "sd", "->", "rLambBack", ",", "sd", "->", "rb", ")", ";", "if", "(", "sd", "->", "tf", "!=", "NULL", ")", "extract_diffuse", "(", "&", "sd", "->", "tLamb", ",", "sd", "->", "tf", ")", ";", "if", "(", "sd", "->", "tb", "!=", "NULL", ")", "extract_diffuse", "(", "&", "sd", "->", "tLamb", ",", "sd", "->", "tb", ")", ";", "return", "SDEnone", ";", "}" ]
Load a variable-resolution BSDF tree from an open XML file
[ "Load", "a", "variable", "-", "resolution", "BSDF", "tree", "from", "an", "open", "XML", "file" ]
[ "/* basic checks and tensor rank */", "/* load BSDF components */", "/* just visible for now */", "/* separate diffuse components */", "/* return success */" ]
[ { "param": "sd", "type": "SDData" }, { "param": "wtl", "type": "ezxml_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sd", "type": "SDData", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "wtl", "type": "ezxml_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3548014c6a35b8a4b63374ef8b6dea755fb9275b
kalyanam-FMTGA/ray-original
src/rt/mx_func.c
[ "BSD-3-Clause-LBNL" ]
C
mx_func
int
extern int mx_func( /* compute mixture function */ register OBJREC *m, RAY *r ) { OBJECT obj; register int i; double coef; OBJECT mod[2]; register MFUNC *mf; if (m->oargs.nsargs < 4) objerror(m, USER, "bad # arguments"); obj = objndx(m); for (i = 0; i < 2; i++) if (!strcmp(m->oargs.sarg[i], VOIDID)) mod[i] = OVOID; else if ((mod[i] = lastmod(obj, m->oargs.sarg[i])) == OVOID) { sprintf(errmsg, "undefined modifier \"%s\"", m->oargs.sarg[i]); objerror(m, USER, errmsg); } mf = getfunc(m, 3, 0x4, 0); setfunc(m, r); errno = 0; coef = evalue(mf->ep[0]); if (errno == EDOM || errno == ERANGE) { objerror(m, WARNING, "compute error"); return(0); } if (raymixture(r, mod[0], mod[1], coef)) { if (m->omod != OVOID) objerror(m, USER, "inappropriate modifier"); return(1); } return(0); }
/* * A mixture function is specified: * * modifier mixfunc name * 4+ foremod backmod varname vfname xf * 0 * n A1 A2 .. * * Vfname is the name of the file where the variable definition * can be found. The list of real arguments can be accessed by * definitions in the file. The xf is a transformation * to get from the original coordinates to the current coordinates. */
A mixture function is specified: modifier mixfunc name 4+ foremod backmod varname vfname xf 0 n A1 A2 Vfname is the name of the file where the variable definition can be found. The list of real arguments can be accessed by definitions in the file. The xf is a transformation to get from the original coordinates to the current coordinates.
[ "A", "mixture", "function", "is", "specified", ":", "modifier", "mixfunc", "name", "4", "+", "foremod", "backmod", "varname", "vfname", "xf", "0", "n", "A1", "A2", "Vfname", "is", "the", "name", "of", "the", "file", "where", "the", "variable", "definition", "can", "be", "found", ".", "The", "list", "of", "real", "arguments", "can", "be", "accessed", "by", "definitions", "in", "the", "file", ".", "The", "xf", "is", "a", "transformation", "to", "get", "from", "the", "original", "coordinates", "to", "the", "current", "coordinates", "." ]
extern int mx_func( register OBJREC *m, RAY *r ) { OBJECT obj; register int i; double coef; OBJECT mod[2]; register MFUNC *mf; if (m->oargs.nsargs < 4) objerror(m, USER, "bad # arguments"); obj = objndx(m); for (i = 0; i < 2; i++) if (!strcmp(m->oargs.sarg[i], VOIDID)) mod[i] = OVOID; else if ((mod[i] = lastmod(obj, m->oargs.sarg[i])) == OVOID) { sprintf(errmsg, "undefined modifier \"%s\"", m->oargs.sarg[i]); objerror(m, USER, errmsg); } mf = getfunc(m, 3, 0x4, 0); setfunc(m, r); errno = 0; coef = evalue(mf->ep[0]); if (errno == EDOM || errno == ERANGE) { objerror(m, WARNING, "compute error"); return(0); } if (raymixture(r, mod[0], mod[1], coef)) { if (m->omod != OVOID) objerror(m, USER, "inappropriate modifier"); return(1); } return(0); }
[ "extern", "int", "mx_func", "(", "register", "OBJREC", "*", "m", ",", "RAY", "*", "r", ")", "{", "OBJECT", "obj", ";", "register", "int", "i", ";", "double", "coef", ";", "OBJECT", "mod", "[", "2", "]", ";", "register", "MFUNC", "*", "mf", ";", "if", "(", "m", "->", "oargs", ".", "nsargs", "<", "4", ")", "objerror", "(", "m", ",", "USER", ",", "\"", "\"", ")", ";", "obj", "=", "objndx", "(", "m", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "2", ";", "i", "++", ")", "if", "(", "!", "strcmp", "(", "m", "->", "oargs", ".", "sarg", "[", "i", "]", ",", "VOIDID", ")", ")", "mod", "[", "i", "]", "=", "OVOID", ";", "else", "if", "(", "(", "mod", "[", "i", "]", "=", "lastmod", "(", "obj", ",", "m", "->", "oargs", ".", "sarg", "[", "i", "]", ")", ")", "==", "OVOID", ")", "{", "sprintf", "(", "errmsg", ",", "\"", "\\\"", "\\\"", "\"", ",", "m", "->", "oargs", ".", "sarg", "[", "i", "]", ")", ";", "objerror", "(", "m", ",", "USER", ",", "errmsg", ")", ";", "}", "mf", "=", "getfunc", "(", "m", ",", "3", ",", "0x4", ",", "0", ")", ";", "setfunc", "(", "m", ",", "r", ")", ";", "errno", "=", "0", ";", "coef", "=", "evalue", "(", "mf", "->", "ep", "[", "0", "]", ")", ";", "if", "(", "errno", "==", "EDOM", "||", "errno", "==", "ERANGE", ")", "{", "objerror", "(", "m", ",", "WARNING", ",", "\"", "\"", ")", ";", "return", "(", "0", ")", ";", "}", "if", "(", "raymixture", "(", "r", ",", "mod", "[", "0", "]", ",", "mod", "[", "1", "]", ",", "coef", ")", ")", "{", "if", "(", "m", "->", "omod", "!=", "OVOID", ")", "objerror", "(", "m", ",", "USER", ",", "\"", "\"", ")", ";", "return", "(", "1", ")", ";", "}", "return", "(", "0", ")", ";", "}" ]
A mixture function is specified: modifier mixfunc name 4+ foremod backmod varname vfname xf 0 n A1 A2 ..
[ "A", "mixture", "function", "is", "specified", ":", "modifier", "mixfunc", "name", "4", "+", "foremod", "backmod", "varname", "vfname", "xf", "0", "n", "A1", "A2", ".." ]
[ "/* compute mixture function */" ]
[ { "param": "m", "type": "OBJREC" }, { "param": "r", "type": "RAY" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "m", "type": "OBJREC", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "r", "type": "RAY", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
48790131432876e1098cc82304e85001b5b8b666
kalyanam-FMTGA/ray-original
src/cv/bsdfmesh.c
[ "BSD-3-Clause-LBNL" ]
C
new_migration
MIGRATION
static MIGRATION * new_migration(RBFNODE *from_rbf, RBFNODE *to_rbf) { size_t memlen = sizeof(MIGRATION) + sizeof(float)*(from_rbf->nrbf*to_rbf->nrbf - 1); MIGRATION *newmig; #ifdef _WIN32 if (nprocs > 1) fprintf(stderr, "%s: warning - multiprocessing not supported\n", progname); nprocs = 1; newmig = (MIGRATION *)malloc(memlen); #else if (nprocs <= 1) { /* single process? */ newmig = (MIGRATION *)malloc(memlen); } else { /* else need to share memory */ newmig = (MIGRATION *)mmap(NULL, memlen, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0); if ((void *)newmig == MAP_FAILED) newmig = NULL; } #endif if (newmig == NULL) { fprintf(stderr, "%s: cannot allocate new migration\n", progname); exit(1); } newmig->rbfv[0] = from_rbf; newmig->rbfv[1] = to_rbf; /* insert in edge lists */ newmig->enxt[0] = from_rbf->ejl; from_rbf->ejl = newmig; newmig->enxt[1] = to_rbf->ejl; to_rbf->ejl = newmig; newmig->next = mig_list; /* push onto global list */ return(mig_list = newmig); }
/* Create a new migration holder (sharing memory for multiprocessing) */
Create a new migration holder (sharing memory for multiprocessing)
[ "Create", "a", "new", "migration", "holder", "(", "sharing", "memory", "for", "multiprocessing", ")" ]
static MIGRATION * new_migration(RBFNODE *from_rbf, RBFNODE *to_rbf) { size_t memlen = sizeof(MIGRATION) + sizeof(float)*(from_rbf->nrbf*to_rbf->nrbf - 1); MIGRATION *newmig; #ifdef _WIN32 if (nprocs > 1) fprintf(stderr, "%s: warning - multiprocessing not supported\n", progname); nprocs = 1; newmig = (MIGRATION *)malloc(memlen); #else if (nprocs <= 1) { newmig = (MIGRATION *)malloc(memlen); } else { newmig = (MIGRATION *)mmap(NULL, memlen, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0); if ((void *)newmig == MAP_FAILED) newmig = NULL; } #endif if (newmig == NULL) { fprintf(stderr, "%s: cannot allocate new migration\n", progname); exit(1); } newmig->rbfv[0] = from_rbf; newmig->rbfv[1] = to_rbf; newmig->enxt[0] = from_rbf->ejl; from_rbf->ejl = newmig; newmig->enxt[1] = to_rbf->ejl; to_rbf->ejl = newmig; newmig->next = mig_list; return(mig_list = newmig); }
[ "static", "MIGRATION", "*", "new_migration", "(", "RBFNODE", "*", "from_rbf", ",", "RBFNODE", "*", "to_rbf", ")", "{", "size_t", "memlen", "=", "sizeof", "(", "MIGRATION", ")", "+", "sizeof", "(", "float", ")", "*", "(", "from_rbf", "->", "nrbf", "*", "to_rbf", "->", "nrbf", "-", "1", ")", ";", "MIGRATION", "*", "newmig", ";", "#ifdef", "_WIN32", "if", "(", "nprocs", ">", "1", ")", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "progname", ")", ";", "nprocs", "=", "1", ";", "newmig", "=", "(", "MIGRATION", "*", ")", "malloc", "(", "memlen", ")", ";", "#else", "if", "(", "nprocs", "<=", "1", ")", "{", "newmig", "=", "(", "MIGRATION", "*", ")", "malloc", "(", "memlen", ")", ";", "}", "else", "{", "newmig", "=", "(", "MIGRATION", "*", ")", "mmap", "(", "NULL", ",", "memlen", ",", "PROT_READ", "|", "PROT_WRITE", ",", "MAP_ANON", "|", "MAP_SHARED", ",", "-1", ",", "0", ")", ";", "if", "(", "(", "void", "*", ")", "newmig", "==", "MAP_FAILED", ")", "newmig", "=", "NULL", ";", "}", "#endif", "if", "(", "newmig", "==", "NULL", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "progname", ")", ";", "exit", "(", "1", ")", ";", "}", "newmig", "->", "rbfv", "[", "0", "]", "=", "from_rbf", ";", "newmig", "->", "rbfv", "[", "1", "]", "=", "to_rbf", ";", "newmig", "->", "enxt", "[", "0", "]", "=", "from_rbf", "->", "ejl", ";", "from_rbf", "->", "ejl", "=", "newmig", ";", "newmig", "->", "enxt", "[", "1", "]", "=", "to_rbf", "->", "ejl", ";", "to_rbf", "->", "ejl", "=", "newmig", ";", "newmig", "->", "next", "=", "mig_list", ";", "return", "(", "mig_list", "=", "newmig", ")", ";", "}" ]
Create a new migration holder (sharing memory for multiprocessing)
[ "Create", "a", "new", "migration", "holder", "(", "sharing", "memory", "for", "multiprocessing", ")" ]
[ "/* single process? */", "/* else need to share memory */", "/* insert in edge lists */", "/* push onto global list */" ]
[ { "param": "from_rbf", "type": "RBFNODE" }, { "param": "to_rbf", "type": "RBFNODE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "from_rbf", "type": "RBFNODE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "to_rbf", "type": "RBFNODE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
48790131432876e1098cc82304e85001b5b8b666
kalyanam-FMTGA/ray-original
src/cv/bsdfmesh.c
[ "BSD-3-Clause-LBNL" ]
C
msrt_cmp
int
static int msrt_cmp(void *b, const void *p1, const void *p2) { PRICEMAT *pm = (PRICEMAT *)b; int ri = ((const short *)p1 - pm->sord) / pm->ncols; float c1 = pricerow(pm,ri)[*(const short *)p1]; float c2 = pricerow(pm,ri)[*(const short *)p2]; if (c1 > c2) return(1); if (c1 < c2) return(-1); return(0); }
/* Comparison routine needed for sorting price row */
Comparison routine needed for sorting price row
[ "Comparison", "routine", "needed", "for", "sorting", "price", "row" ]
static int msrt_cmp(void *b, const void *p1, const void *p2) { PRICEMAT *pm = (PRICEMAT *)b; int ri = ((const short *)p1 - pm->sord) / pm->ncols; float c1 = pricerow(pm,ri)[*(const short *)p1]; float c2 = pricerow(pm,ri)[*(const short *)p2]; if (c1 > c2) return(1); if (c1 < c2) return(-1); return(0); }
[ "static", "int", "msrt_cmp", "(", "void", "*", "b", ",", "const", "void", "*", "p1", ",", "const", "void", "*", "p2", ")", "{", "PRICEMAT", "*", "pm", "=", "(", "PRICEMAT", "*", ")", "b", ";", "int", "ri", "=", "(", "(", "const", "short", "*", ")", "p1", "-", "pm", "->", "sord", ")", "/", "pm", "->", "ncols", ";", "float", "c1", "=", "pricerow", "(", "pm", ",", "ri", ")", "[", "*", "(", "const", "short", "*", ")", "p1", "]", ";", "float", "c2", "=", "pricerow", "(", "pm", ",", "ri", ")", "[", "*", "(", "const", "short", "*", ")", "p2", "]", ";", "if", "(", "c1", ">", "c2", ")", "return", "(", "1", ")", ";", "if", "(", "c1", "<", "c2", ")", "return", "(", "-1", ")", ";", "return", "(", "0", ")", ";", "}" ]
Comparison routine needed for sorting price row
[ "Comparison", "routine", "needed", "for", "sorting", "price", "row" ]
[]
[ { "param": "b", "type": "void" }, { "param": "p1", "type": "void" }, { "param": "p2", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "b", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "p1", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "p2", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
48790131432876e1098cc82304e85001b5b8b666
kalyanam-FMTGA/ray-original
src/cv/bsdfmesh.c
[ "BSD-3-Clause-LBNL" ]
C
price_routes
void
static void price_routes(PRICEMAT *pm, const RBFNODE *from_rbf, const RBFNODE *to_rbf) { FVECT *vto = (FVECT *)malloc(sizeof(FVECT) * to_rbf->nrbf); int i, j; pm->nrows = from_rbf->nrbf; pm->ncols = to_rbf->nrbf; pm->price = (float *)malloc(sizeof(float) * pm->nrows*pm->ncols); pm->sord = (short *)malloc(sizeof(short) * pm->nrows*pm->ncols); if ((pm->price == NULL) | (pm->sord == NULL) | (vto == NULL)) { fprintf(stderr, "%s: Out of memory in migration_costs()\n", progname); exit(1); } for (j = to_rbf->nrbf; j--; ) /* save repetitive ops. */ ovec_from_pos(vto[j], to_rbf->rbfa[j].gx, to_rbf->rbfa[j].gy); for (i = from_rbf->nrbf; i--; ) { const double from_ang = R2ANG(from_rbf->rbfa[i].crad); FVECT vfrom; ovec_from_pos(vfrom, from_rbf->rbfa[i].gx, from_rbf->rbfa[i].gy); for (j = to_rbf->nrbf; j--; ) { double dprod = DOT(vfrom, vto[j]); pricerow(pm,i)[j] = ((dprod >= 1.) ? .0 : acos(dprod)) + fabs(R2ANG(to_rbf->rbfa[j].crad) - from_ang); psortrow(pm,i)[j] = j; } qsort_r(psortrow(pm,i), pm->ncols, sizeof(short), pm, &msrt_cmp); } free(vto); }
/* Compute (and allocate) migration price matrix for optimization */
Compute (and allocate) migration price matrix for optimization
[ "Compute", "(", "and", "allocate", ")", "migration", "price", "matrix", "for", "optimization" ]
static void price_routes(PRICEMAT *pm, const RBFNODE *from_rbf, const RBFNODE *to_rbf) { FVECT *vto = (FVECT *)malloc(sizeof(FVECT) * to_rbf->nrbf); int i, j; pm->nrows = from_rbf->nrbf; pm->ncols = to_rbf->nrbf; pm->price = (float *)malloc(sizeof(float) * pm->nrows*pm->ncols); pm->sord = (short *)malloc(sizeof(short) * pm->nrows*pm->ncols); if ((pm->price == NULL) | (pm->sord == NULL) | (vto == NULL)) { fprintf(stderr, "%s: Out of memory in migration_costs()\n", progname); exit(1); } for (j = to_rbf->nrbf; j--; ) ovec_from_pos(vto[j], to_rbf->rbfa[j].gx, to_rbf->rbfa[j].gy); for (i = from_rbf->nrbf; i--; ) { const double from_ang = R2ANG(from_rbf->rbfa[i].crad); FVECT vfrom; ovec_from_pos(vfrom, from_rbf->rbfa[i].gx, from_rbf->rbfa[i].gy); for (j = to_rbf->nrbf; j--; ) { double dprod = DOT(vfrom, vto[j]); pricerow(pm,i)[j] = ((dprod >= 1.) ? .0 : acos(dprod)) + fabs(R2ANG(to_rbf->rbfa[j].crad) - from_ang); psortrow(pm,i)[j] = j; } qsort_r(psortrow(pm,i), pm->ncols, sizeof(short), pm, &msrt_cmp); } free(vto); }
[ "static", "void", "price_routes", "(", "PRICEMAT", "*", "pm", ",", "const", "RBFNODE", "*", "from_rbf", ",", "const", "RBFNODE", "*", "to_rbf", ")", "{", "FVECT", "*", "vto", "=", "(", "FVECT", "*", ")", "malloc", "(", "sizeof", "(", "FVECT", ")", "*", "to_rbf", "->", "nrbf", ")", ";", "int", "i", ",", "j", ";", "pm", "->", "nrows", "=", "from_rbf", "->", "nrbf", ";", "pm", "->", "ncols", "=", "to_rbf", "->", "nrbf", ";", "pm", "->", "price", "=", "(", "float", "*", ")", "malloc", "(", "sizeof", "(", "float", ")", "*", "pm", "->", "nrows", "*", "pm", "->", "ncols", ")", ";", "pm", "->", "sord", "=", "(", "short", "*", ")", "malloc", "(", "sizeof", "(", "short", ")", "*", "pm", "->", "nrows", "*", "pm", "->", "ncols", ")", ";", "if", "(", "(", "pm", "->", "price", "==", "NULL", ")", "|", "(", "pm", "->", "sord", "==", "NULL", ")", "|", "(", "vto", "==", "NULL", ")", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "progname", ")", ";", "exit", "(", "1", ")", ";", "}", "for", "(", "j", "=", "to_rbf", "->", "nrbf", ";", "j", "--", ";", ")", "ovec_from_pos", "(", "vto", "[", "j", "]", ",", "to_rbf", "->", "rbfa", "[", "j", "]", ".", "gx", ",", "to_rbf", "->", "rbfa", "[", "j", "]", ".", "gy", ")", ";", "for", "(", "i", "=", "from_rbf", "->", "nrbf", ";", "i", "--", ";", ")", "{", "const", "double", "from_ang", "=", "R2ANG", "(", "from_rbf", "->", "rbfa", "[", "i", "]", ".", "crad", ")", ";", "FVECT", "vfrom", ";", "ovec_from_pos", "(", "vfrom", ",", "from_rbf", "->", "rbfa", "[", "i", "]", ".", "gx", ",", "from_rbf", "->", "rbfa", "[", "i", "]", ".", "gy", ")", ";", "for", "(", "j", "=", "to_rbf", "->", "nrbf", ";", "j", "--", ";", ")", "{", "double", "dprod", "=", "DOT", "(", "vfrom", ",", "vto", "[", "j", "]", ")", ";", "pricerow", "(", "pm", ",", "i", ")", "[", "j", "]", "=", "(", "(", "dprod", ">=", "1.", ")", "?", ".0", ":", "acos", "(", "dprod", ")", ")", "+", "fabs", "(", "R2ANG", "(", "to_rbf", "->", "rbfa", "[", "j", "]", ".", "crad", ")", "-", "from_ang", ")", ";", "psortrow", "(", "pm", ",", "i", ")", "[", "j", "]", "=", "j", ";", "}", "qsort_r", "(", "psortrow", "(", "pm", ",", "i", ")", ",", "pm", "->", "ncols", ",", "sizeof", "(", "short", ")", ",", "pm", ",", "&", "msrt_cmp", ")", ";", "}", "free", "(", "vto", ")", ";", "}" ]
Compute (and allocate) migration price matrix for optimization
[ "Compute", "(", "and", "allocate", ")", "migration", "price", "matrix", "for", "optimization" ]
[ "/* save repetitive ops. */" ]
[ { "param": "pm", "type": "PRICEMAT" }, { "param": "from_rbf", "type": "RBFNODE" }, { "param": "to_rbf", "type": "RBFNODE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pm", "type": "PRICEMAT", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "from_rbf", "type": "RBFNODE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "to_rbf", "type": "RBFNODE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
48790131432876e1098cc82304e85001b5b8b666
kalyanam-FMTGA/ray-original
src/cv/bsdfmesh.c
[ "BSD-3-Clause-LBNL" ]
C
min_cost
double
static double min_cost(double amt2move, const double *avail, const PRICEMAT *pm, int s) { double total_cost = 0; int j; if (amt2move <= FTINY) /* pre-emptive check */ return(.0); /* move cheapest first */ for (j = 0; j < pm->ncols && amt2move > FTINY; j++) { int d = psortrow(pm,s)[j]; double amt = (amt2move < avail[d]) ? amt2move : avail[d]; total_cost += amt * pricerow(pm,s)[d]; amt2move -= amt; } return(total_cost); }
/* Compute minimum (optimistic) cost for moving the given source material */
Compute minimum (optimistic) cost for moving the given source material
[ "Compute", "minimum", "(", "optimistic", ")", "cost", "for", "moving", "the", "given", "source", "material" ]
static double min_cost(double amt2move, const double *avail, const PRICEMAT *pm, int s) { double total_cost = 0; int j; if (amt2move <= FTINY) return(.0); for (j = 0; j < pm->ncols && amt2move > FTINY; j++) { int d = psortrow(pm,s)[j]; double amt = (amt2move < avail[d]) ? amt2move : avail[d]; total_cost += amt * pricerow(pm,s)[d]; amt2move -= amt; } return(total_cost); }
[ "static", "double", "min_cost", "(", "double", "amt2move", ",", "const", "double", "*", "avail", ",", "const", "PRICEMAT", "*", "pm", ",", "int", "s", ")", "{", "double", "total_cost", "=", "0", ";", "int", "j", ";", "if", "(", "amt2move", "<=", "FTINY", ")", "return", "(", ".0", ")", ";", "for", "(", "j", "=", "0", ";", "j", "<", "pm", "->", "ncols", "&&", "amt2move", ">", "FTINY", ";", "j", "++", ")", "{", "int", "d", "=", "psortrow", "(", "pm", ",", "s", ")", "[", "j", "]", ";", "double", "amt", "=", "(", "amt2move", "<", "avail", "[", "d", "]", ")", "?", "amt2move", ":", "avail", "[", "d", "]", ";", "total_cost", "+=", "amt", "*", "pricerow", "(", "pm", ",", "s", ")", "[", "d", "]", ";", "amt2move", "-=", "amt", ";", "}", "return", "(", "total_cost", ")", ";", "}" ]
Compute minimum (optimistic) cost for moving the given source material
[ "Compute", "minimum", "(", "optimistic", ")", "cost", "for", "moving", "the", "given", "source", "material" ]
[ "/* pre-emptive check */", "/* move cheapest first */" ]
[ { "param": "amt2move", "type": "double" }, { "param": "avail", "type": "double" }, { "param": "pm", "type": "PRICEMAT" }, { "param": "s", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "amt2move", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "avail", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pm", "type": "PRICEMAT", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "s", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
48790131432876e1098cc82304e85001b5b8b666
kalyanam-FMTGA/ray-original
src/cv/bsdfmesh.c
[ "BSD-3-Clause-LBNL" ]
C
migration_step
double
static double migration_step(MIGRATION *mig, double *src_rem, double *dst_rem, const PRICEMAT *pm) { const double maxamt = 1./(double)pm->ncols; const double minamt = maxamt*5e-6; double *src_cost; struct { int s, d; /* source and destination */ double price; /* price estimate per amount moved */ double amt; /* amount we can move */ } cur, best; int i; /* allocate cost array */ src_cost = (double *)malloc(sizeof(double)*pm->nrows); if (src_cost == NULL) { fprintf(stderr, "%s: Out of memory in migration_step()\n", progname); exit(1); } for (i = pm->nrows; i--; ) /* starting costs for diff. */ src_cost[i] = min_cost(src_rem[i], dst_rem, pm, i); /* find best source & dest. */ best.s = best.d = -1; best.price = FHUGE; best.amt = 0; for (cur.s = pm->nrows; cur.s--; ) { double cost_others = 0; if (src_rem[cur.s] <= minamt) continue; /* examine cheapest dest. */ for (i = 0; i < pm->ncols; i++) if (dst_rem[ cur.d = psortrow(pm,cur.s)[i] ] > minamt) break; if (i >= pm->ncols) break; if ((cur.price = pricerow(pm,cur.s)[cur.d]) >= best.price) continue; /* no point checking further */ cur.amt = (src_rem[cur.s] < dst_rem[cur.d]) ? src_rem[cur.s] : dst_rem[cur.d]; if (cur.amt > maxamt) cur.amt = maxamt; dst_rem[cur.d] -= cur.amt; /* add up differential costs */ for (i = pm->nrows; i--; ) if (i != cur.s) cost_others += min_cost(src_rem[i], dst_rem, pm, i) - src_cost[i]; dst_rem[cur.d] += cur.amt; /* undo trial move */ cur.price += cost_others/cur.amt; /* adjust effective price */ if (cur.price < best.price) /* are we better than best? */ best = cur; } free(src_cost); /* finish up */ if ((best.s < 0) | (best.d < 0)) /* nothing left to move? */ return(.0); /* else make the actual move */ mtx_coef(mig,best.s,best.d) += best.amt; src_rem[best.s] -= best.amt; dst_rem[best.d] -= best.amt; return(best.amt); }
/* Take a step in migration by choosing optimal bucket to transfer */
Take a step in migration by choosing optimal bucket to transfer
[ "Take", "a", "step", "in", "migration", "by", "choosing", "optimal", "bucket", "to", "transfer" ]
static double migration_step(MIGRATION *mig, double *src_rem, double *dst_rem, const PRICEMAT *pm) { const double maxamt = 1./(double)pm->ncols; const double minamt = maxamt*5e-6; double *src_cost; struct { int s, d; double price; double amt; } cur, best; int i; src_cost = (double *)malloc(sizeof(double)*pm->nrows); if (src_cost == NULL) { fprintf(stderr, "%s: Out of memory in migration_step()\n", progname); exit(1); } for (i = pm->nrows; i--; ) src_cost[i] = min_cost(src_rem[i], dst_rem, pm, i); best.s = best.d = -1; best.price = FHUGE; best.amt = 0; for (cur.s = pm->nrows; cur.s--; ) { double cost_others = 0; if (src_rem[cur.s] <= minamt) continue; for (i = 0; i < pm->ncols; i++) if (dst_rem[ cur.d = psortrow(pm,cur.s)[i] ] > minamt) break; if (i >= pm->ncols) break; if ((cur.price = pricerow(pm,cur.s)[cur.d]) >= best.price) continue; cur.amt = (src_rem[cur.s] < dst_rem[cur.d]) ? src_rem[cur.s] : dst_rem[cur.d]; if (cur.amt > maxamt) cur.amt = maxamt; dst_rem[cur.d] -= cur.amt; for (i = pm->nrows; i--; ) if (i != cur.s) cost_others += min_cost(src_rem[i], dst_rem, pm, i) - src_cost[i]; dst_rem[cur.d] += cur.amt; cur.price += cost_others/cur.amt; if (cur.price < best.price) best = cur; } free(src_cost); if ((best.s < 0) | (best.d < 0)) return(.0); mtx_coef(mig,best.s,best.d) += best.amt; src_rem[best.s] -= best.amt; dst_rem[best.d] -= best.amt; return(best.amt); }
[ "static", "double", "migration_step", "(", "MIGRATION", "*", "mig", ",", "double", "*", "src_rem", ",", "double", "*", "dst_rem", ",", "const", "PRICEMAT", "*", "pm", ")", "{", "const", "double", "maxamt", "=", "1.", "/", "(", "double", ")", "pm", "->", "ncols", ";", "const", "double", "minamt", "=", "maxamt", "*", "5e-6", ";", "double", "*", "src_cost", ";", "struct", "{", "int", "s", ",", "d", ";", "double", "price", ";", "double", "amt", ";", "}", "cur", ",", "best", ";", "int", "i", ";", "src_cost", "=", "(", "double", "*", ")", "malloc", "(", "sizeof", "(", "double", ")", "*", "pm", "->", "nrows", ")", ";", "if", "(", "src_cost", "==", "NULL", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "progname", ")", ";", "exit", "(", "1", ")", ";", "}", "for", "(", "i", "=", "pm", "->", "nrows", ";", "i", "--", ";", ")", "src_cost", "[", "i", "]", "=", "min_cost", "(", "src_rem", "[", "i", "]", ",", "dst_rem", ",", "pm", ",", "i", ")", ";", "best", ".", "s", "=", "best", ".", "d", "=", "-1", ";", "best", ".", "price", "=", "FHUGE", ";", "best", ".", "amt", "=", "0", ";", "for", "(", "cur", ".", "s", "=", "pm", "->", "nrows", ";", "cur", ".", "s", "--", ";", ")", "{", "double", "cost_others", "=", "0", ";", "if", "(", "src_rem", "[", "cur", ".", "s", "]", "<=", "minamt", ")", "continue", ";", "for", "(", "i", "=", "0", ";", "i", "<", "pm", "->", "ncols", ";", "i", "++", ")", "if", "(", "dst_rem", "[", "cur", ".", "d", "=", "psortrow", "(", "pm", ",", "cur", ".", "s", ")", "[", "i", "]", "]", ">", "minamt", ")", "break", ";", "if", "(", "i", ">=", "pm", "->", "ncols", ")", "break", ";", "if", "(", "(", "cur", ".", "price", "=", "pricerow", "(", "pm", ",", "cur", ".", "s", ")", "[", "cur", ".", "d", "]", ")", ">=", "best", ".", "price", ")", "continue", ";", "cur", ".", "amt", "=", "(", "src_rem", "[", "cur", ".", "s", "]", "<", "dst_rem", "[", "cur", ".", "d", "]", ")", "?", "src_rem", "[", "cur", ".", "s", "]", ":", "dst_rem", "[", "cur", ".", "d", "]", ";", "if", "(", "cur", ".", "amt", ">", "maxamt", ")", "cur", ".", "amt", "=", "maxamt", ";", "dst_rem", "[", "cur", ".", "d", "]", "-=", "cur", ".", "amt", ";", "for", "(", "i", "=", "pm", "->", "nrows", ";", "i", "--", ";", ")", "if", "(", "i", "!=", "cur", ".", "s", ")", "cost_others", "+=", "min_cost", "(", "src_rem", "[", "i", "]", ",", "dst_rem", ",", "pm", ",", "i", ")", "-", "src_cost", "[", "i", "]", ";", "dst_rem", "[", "cur", ".", "d", "]", "+=", "cur", ".", "amt", ";", "cur", ".", "price", "+=", "cost_others", "/", "cur", ".", "amt", ";", "if", "(", "cur", ".", "price", "<", "best", ".", "price", ")", "best", "=", "cur", ";", "}", "free", "(", "src_cost", ")", ";", "if", "(", "(", "best", ".", "s", "<", "0", ")", "|", "(", "best", ".", "d", "<", "0", ")", ")", "return", "(", ".0", ")", ";", "mtx_coef", "(", "mig", ",", "best", ".", "s", ",", "best", ".", "d", ")", "+=", "best", ".", "amt", ";", "src_rem", "[", "best", ".", "s", "]", "-=", "best", ".", "amt", ";", "dst_rem", "[", "best", ".", "d", "]", "-=", "best", ".", "amt", ";", "return", "(", "best", ".", "amt", ")", ";", "}" ]
Take a step in migration by choosing optimal bucket to transfer
[ "Take", "a", "step", "in", "migration", "by", "choosing", "optimal", "bucket", "to", "transfer" ]
[ "/* source and destination */", "/* price estimate per amount moved */", "/* amount we can move */", "/* allocate cost array */", "/* starting costs for diff. */", "/* find best source & dest. */", "/* examine cheapest dest. */", "/* no point checking further */", "/* add up differential costs */", "/* undo trial move */", "/* adjust effective price */", "/* are we better than best? */", "/* finish up */", "/* nothing left to move? */", "/* else make the actual move */" ]
[ { "param": "mig", "type": "MIGRATION" }, { "param": "src_rem", "type": "double" }, { "param": "dst_rem", "type": "double" }, { "param": "pm", "type": "PRICEMAT" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "mig", "type": "MIGRATION", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "src_rem", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "dst_rem", "type": "double", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pm", "type": "PRICEMAT", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
48790131432876e1098cc82304e85001b5b8b666
kalyanam-FMTGA/ray-original
src/cv/bsdfmesh.c
[ "BSD-3-Clause-LBNL" ]
C
create_migration
MIGRATION
static MIGRATION * create_migration(RBFNODE *from_rbf, RBFNODE *to_rbf) { const double end_thresh = 5e-6; PRICEMAT pmtx; MIGRATION *newmig; double *src_rem, *dst_rem; double total_rem = 1., move_amt; int i, j; /* check if exists already */ for (newmig = from_rbf->ejl; newmig != NULL; newmig = nextedge(from_rbf,newmig)) if (newmig->rbfv[1] == to_rbf) return(NULL); /* else allocate */ #ifdef DEBUG fprintf(stderr, "Building path from (theta,phi) (%.0f,%.0f) ", get_theta180(from_rbf->invec), get_phi360(from_rbf->invec)); fprintf(stderr, "to (%.0f,%.0f) with %d x %d matrix\n", get_theta180(to_rbf->invec), get_phi360(to_rbf->invec), from_rbf->nrbf, to_rbf->nrbf); #endif newmig = new_migration(from_rbf, to_rbf); if (run_subprocess()) return(newmig); /* child continues */ price_routes(&pmtx, from_rbf, to_rbf); src_rem = (double *)malloc(sizeof(double)*from_rbf->nrbf); dst_rem = (double *)malloc(sizeof(double)*to_rbf->nrbf); if ((src_rem == NULL) | (dst_rem == NULL)) { fprintf(stderr, "%s: Out of memory in create_migration()\n", progname); exit(1); } /* starting quantities */ memset(newmig->mtx, 0, sizeof(float)*from_rbf->nrbf*to_rbf->nrbf); for (i = from_rbf->nrbf; i--; ) src_rem[i] = rbf_volume(&from_rbf->rbfa[i]) / from_rbf->vtotal; for (j = to_rbf->nrbf; j--; ) dst_rem[j] = rbf_volume(&to_rbf->rbfa[j]) / to_rbf->vtotal; do { /* move a bit at a time */ move_amt = migration_step(newmig, src_rem, dst_rem, &pmtx); total_rem -= move_amt; } while ((total_rem > end_thresh) & (move_amt > 0)); for (i = from_rbf->nrbf; i--; ) { /* normalize final matrix */ double nf = rbf_volume(&from_rbf->rbfa[i]); if (nf <= FTINY) continue; nf = from_rbf->vtotal / nf; for (j = to_rbf->nrbf; j--; ) mtx_coef(newmig,i,j) *= nf; /* row now sums to 1.0 */ } end_subprocess(); /* exit here if subprocess */ free_routes(&pmtx); /* free working arrays */ free(src_rem); free(dst_rem); return(newmig); }
/* Compute and insert migration along directed edge (may fork child) */
Compute and insert migration along directed edge (may fork child)
[ "Compute", "and", "insert", "migration", "along", "directed", "edge", "(", "may", "fork", "child", ")" ]
static MIGRATION * create_migration(RBFNODE *from_rbf, RBFNODE *to_rbf) { const double end_thresh = 5e-6; PRICEMAT pmtx; MIGRATION *newmig; double *src_rem, *dst_rem; double total_rem = 1., move_amt; int i, j; for (newmig = from_rbf->ejl; newmig != NULL; newmig = nextedge(from_rbf,newmig)) if (newmig->rbfv[1] == to_rbf) return(NULL); #ifdef DEBUG fprintf(stderr, "Building path from (theta,phi) (%.0f,%.0f) ", get_theta180(from_rbf->invec), get_phi360(from_rbf->invec)); fprintf(stderr, "to (%.0f,%.0f) with %d x %d matrix\n", get_theta180(to_rbf->invec), get_phi360(to_rbf->invec), from_rbf->nrbf, to_rbf->nrbf); #endif newmig = new_migration(from_rbf, to_rbf); if (run_subprocess()) return(newmig); price_routes(&pmtx, from_rbf, to_rbf); src_rem = (double *)malloc(sizeof(double)*from_rbf->nrbf); dst_rem = (double *)malloc(sizeof(double)*to_rbf->nrbf); if ((src_rem == NULL) | (dst_rem == NULL)) { fprintf(stderr, "%s: Out of memory in create_migration()\n", progname); exit(1); } memset(newmig->mtx, 0, sizeof(float)*from_rbf->nrbf*to_rbf->nrbf); for (i = from_rbf->nrbf; i--; ) src_rem[i] = rbf_volume(&from_rbf->rbfa[i]) / from_rbf->vtotal; for (j = to_rbf->nrbf; j--; ) dst_rem[j] = rbf_volume(&to_rbf->rbfa[j]) / to_rbf->vtotal; do { move_amt = migration_step(newmig, src_rem, dst_rem, &pmtx); total_rem -= move_amt; } while ((total_rem > end_thresh) & (move_amt > 0)); for (i = from_rbf->nrbf; i--; ) { double nf = rbf_volume(&from_rbf->rbfa[i]); if (nf <= FTINY) continue; nf = from_rbf->vtotal / nf; for (j = to_rbf->nrbf; j--; ) mtx_coef(newmig,i,j) *= nf; } end_subprocess(); free_routes(&pmtx); free(src_rem); free(dst_rem); return(newmig); }
[ "static", "MIGRATION", "*", "create_migration", "(", "RBFNODE", "*", "from_rbf", ",", "RBFNODE", "*", "to_rbf", ")", "{", "const", "double", "end_thresh", "=", "5e-6", ";", "PRICEMAT", "pmtx", ";", "MIGRATION", "*", "newmig", ";", "double", "*", "src_rem", ",", "*", "dst_rem", ";", "double", "total_rem", "=", "1.", ",", "move_amt", ";", "int", "i", ",", "j", ";", "for", "(", "newmig", "=", "from_rbf", "->", "ejl", ";", "newmig", "!=", "NULL", ";", "newmig", "=", "nextedge", "(", "from_rbf", ",", "newmig", ")", ")", "if", "(", "newmig", "->", "rbfv", "[", "1", "]", "==", "to_rbf", ")", "return", "(", "NULL", ")", ";", "#ifdef", "DEBUG", "fprintf", "(", "stderr", ",", "\"", "\"", ",", "get_theta180", "(", "from_rbf", "->", "invec", ")", ",", "get_phi360", "(", "from_rbf", "->", "invec", ")", ")", ";", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "get_theta180", "(", "to_rbf", "->", "invec", ")", ",", "get_phi360", "(", "to_rbf", "->", "invec", ")", ",", "from_rbf", "->", "nrbf", ",", "to_rbf", "->", "nrbf", ")", ";", "#endif", "newmig", "=", "new_migration", "(", "from_rbf", ",", "to_rbf", ")", ";", "if", "(", "run_subprocess", "(", ")", ")", "return", "(", "newmig", ")", ";", "price_routes", "(", "&", "pmtx", ",", "from_rbf", ",", "to_rbf", ")", ";", "src_rem", "=", "(", "double", "*", ")", "malloc", "(", "sizeof", "(", "double", ")", "*", "from_rbf", "->", "nrbf", ")", ";", "dst_rem", "=", "(", "double", "*", ")", "malloc", "(", "sizeof", "(", "double", ")", "*", "to_rbf", "->", "nrbf", ")", ";", "if", "(", "(", "src_rem", "==", "NULL", ")", "|", "(", "dst_rem", "==", "NULL", ")", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "progname", ")", ";", "exit", "(", "1", ")", ";", "}", "memset", "(", "newmig", "->", "mtx", ",", "0", ",", "sizeof", "(", "float", ")", "*", "from_rbf", "->", "nrbf", "*", "to_rbf", "->", "nrbf", ")", ";", "for", "(", "i", "=", "from_rbf", "->", "nrbf", ";", "i", "--", ";", ")", "src_rem", "[", "i", "]", "=", "rbf_volume", "(", "&", "from_rbf", "->", "rbfa", "[", "i", "]", ")", "/", "from_rbf", "->", "vtotal", ";", "for", "(", "j", "=", "to_rbf", "->", "nrbf", ";", "j", "--", ";", ")", "dst_rem", "[", "j", "]", "=", "rbf_volume", "(", "&", "to_rbf", "->", "rbfa", "[", "j", "]", ")", "/", "to_rbf", "->", "vtotal", ";", "do", "{", "move_amt", "=", "migration_step", "(", "newmig", ",", "src_rem", ",", "dst_rem", ",", "&", "pmtx", ")", ";", "total_rem", "-=", "move_amt", ";", "}", "while", "(", "(", "total_rem", ">", "end_thresh", ")", "&", "(", "move_amt", ">", "0", ")", ")", ";", "for", "(", "i", "=", "from_rbf", "->", "nrbf", ";", "i", "--", ";", ")", "{", "double", "nf", "=", "rbf_volume", "(", "&", "from_rbf", "->", "rbfa", "[", "i", "]", ")", ";", "if", "(", "nf", "<=", "FTINY", ")", "continue", ";", "nf", "=", "from_rbf", "->", "vtotal", "/", "nf", ";", "for", "(", "j", "=", "to_rbf", "->", "nrbf", ";", "j", "--", ";", ")", "mtx_coef", "(", "newmig", ",", "i", ",", "j", ")", "*=", "nf", ";", "}", "end_subprocess", "(", ")", ";", "free_routes", "(", "&", "pmtx", ")", ";", "free", "(", "src_rem", ")", ";", "free", "(", "dst_rem", ")", ";", "return", "(", "newmig", ")", ";", "}" ]
Compute and insert migration along directed edge (may fork child)
[ "Compute", "and", "insert", "migration", "along", "directed", "edge", "(", "may", "fork", "child", ")" ]
[ "/* check if exists already */", "/* else allocate */", "/* child continues */", "/* starting quantities */", "/* move a bit at a time */", "/* normalize final matrix */", "/* row now sums to 1.0 */", "/* exit here if subprocess */", "/* free working arrays */" ]
[ { "param": "from_rbf", "type": "RBFNODE" }, { "param": "to_rbf", "type": "RBFNODE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "from_rbf", "type": "RBFNODE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "to_rbf", "type": "RBFNODE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
48790131432876e1098cc82304e85001b5b8b666
kalyanam-FMTGA/ray-original
src/cv/bsdfmesh.c
[ "BSD-3-Clause-LBNL" ]
C
find_chull_vert
RBFNODE
static RBFNODE * find_chull_vert(const RBFNODE *rbf0, const RBFNODE *rbf1) { FVECT vmid, vejn, vp; RBFNODE *rbf, *rbfbest = NULL; double dprod, area2, bestarea2 = FHUGE, bestdprod = -.5; VSUB(vejn, rbf1->invec, rbf0->invec); VADD(vmid, rbf0->invec, rbf1->invec); if (normalize(vejn) == 0 || normalize(vmid) == 0) return(NULL); /* XXX exhaustive search */ /* Find triangle with minimum rotation from perpendicular */ for (rbf = dsf_list; rbf != NULL; rbf = rbf->next) { if ((rbf == rbf0) | (rbf == rbf1)) continue; tri_orient(vp, rbf0->invec, rbf1->invec, rbf->invec); if (DOT(vp, vmid) <= FTINY) continue; /* wrong orientation */ area2 = .25*DOT(vp,vp); VSUB(vp, rbf->invec, rbf0->invec); dprod = -DOT(vp, vejn); VSUM(vp, vp, vejn, dprod); /* above guarantees non-zero */ dprod = DOT(vp, vmid) / VLEN(vp); if (dprod <= bestdprod + FTINY*(1 - 2*(area2 < bestarea2))) continue; /* found better already */ if (overlaps_tri(rbf0, rbf1, rbf)) continue; /* overlaps another triangle */ rbfbest = rbf; bestdprod = dprod; /* new one to beat */ bestarea2 = area2; } return(rbfbest); }
/* Find context hull vertex to complete triangle (oriented call) */
Find context hull vertex to complete triangle (oriented call)
[ "Find", "context", "hull", "vertex", "to", "complete", "triangle", "(", "oriented", "call", ")" ]
static RBFNODE * find_chull_vert(const RBFNODE *rbf0, const RBFNODE *rbf1) { FVECT vmid, vejn, vp; RBFNODE *rbf, *rbfbest = NULL; double dprod, area2, bestarea2 = FHUGE, bestdprod = -.5; VSUB(vejn, rbf1->invec, rbf0->invec); VADD(vmid, rbf0->invec, rbf1->invec); if (normalize(vejn) == 0 || normalize(vmid) == 0) return(NULL); for (rbf = dsf_list; rbf != NULL; rbf = rbf->next) { if ((rbf == rbf0) | (rbf == rbf1)) continue; tri_orient(vp, rbf0->invec, rbf1->invec, rbf->invec); if (DOT(vp, vmid) <= FTINY) continue; area2 = .25*DOT(vp,vp); VSUB(vp, rbf->invec, rbf0->invec); dprod = -DOT(vp, vejn); VSUM(vp, vp, vejn, dprod); dprod = DOT(vp, vmid) / VLEN(vp); if (dprod <= bestdprod + FTINY*(1 - 2*(area2 < bestarea2))) continue; if (overlaps_tri(rbf0, rbf1, rbf)) continue; rbfbest = rbf; bestdprod = dprod; bestarea2 = area2; } return(rbfbest); }
[ "static", "RBFNODE", "*", "find_chull_vert", "(", "const", "RBFNODE", "*", "rbf0", ",", "const", "RBFNODE", "*", "rbf1", ")", "{", "FVECT", "vmid", ",", "vejn", ",", "vp", ";", "RBFNODE", "*", "rbf", ",", "*", "rbfbest", "=", "NULL", ";", "double", "dprod", ",", "area2", ",", "bestarea2", "=", "FHUGE", ",", "bestdprod", "=", "-.5", ";", "VSUB", "(", "vejn", ",", "rbf1", "->", "invec", ",", "rbf0", "->", "invec", ")", ";", "VADD", "(", "vmid", ",", "rbf0", "->", "invec", ",", "rbf1", "->", "invec", ")", ";", "if", "(", "normalize", "(", "vejn", ")", "==", "0", "||", "normalize", "(", "vmid", ")", "==", "0", ")", "return", "(", "NULL", ")", ";", "for", "(", "rbf", "=", "dsf_list", ";", "rbf", "!=", "NULL", ";", "rbf", "=", "rbf", "->", "next", ")", "{", "if", "(", "(", "rbf", "==", "rbf0", ")", "|", "(", "rbf", "==", "rbf1", ")", ")", "continue", ";", "tri_orient", "(", "vp", ",", "rbf0", "->", "invec", ",", "rbf1", "->", "invec", ",", "rbf", "->", "invec", ")", ";", "if", "(", "DOT", "(", "vp", ",", "vmid", ")", "<=", "FTINY", ")", "continue", ";", "area2", "=", ".25", "*", "DOT", "(", "vp", ",", "vp", ")", ";", "VSUB", "(", "vp", ",", "rbf", "->", "invec", ",", "rbf0", "->", "invec", ")", ";", "dprod", "=", "-", "DOT", "(", "vp", ",", "vejn", ")", ";", "VSUM", "(", "vp", ",", "vp", ",", "vejn", ",", "dprod", ")", ";", "dprod", "=", "DOT", "(", "vp", ",", "vmid", ")", "/", "VLEN", "(", "vp", ")", ";", "if", "(", "dprod", "<=", "bestdprod", "+", "FTINY", "*", "(", "1", "-", "2", "*", "(", "area2", "<", "bestarea2", ")", ")", ")", "continue", ";", "if", "(", "overlaps_tri", "(", "rbf0", ",", "rbf1", ",", "rbf", ")", ")", "continue", ";", "rbfbest", "=", "rbf", ";", "bestdprod", "=", "dprod", ";", "bestarea2", "=", "area2", ";", "}", "return", "(", "rbfbest", ")", ";", "}" ]
Find context hull vertex to complete triangle (oriented call)
[ "Find", "context", "hull", "vertex", "to", "complete", "triangle", "(", "oriented", "call", ")" ]
[ "/* XXX exhaustive search */", "/* Find triangle with minimum rotation from perpendicular */", "/* wrong orientation */", "/* above guarantees non-zero */", "/* found better already */", "/* overlaps another triangle */", "/* new one to beat */" ]
[ { "param": "rbf0", "type": "RBFNODE" }, { "param": "rbf1", "type": "RBFNODE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "rbf0", "type": "RBFNODE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "rbf1", "type": "RBFNODE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
48790131432876e1098cc82304e85001b5b8b666
kalyanam-FMTGA/ray-original
src/cv/bsdfmesh.c
[ "BSD-3-Clause-LBNL" ]
C
mesh_from_edge
void
static void mesh_from_edge(MIGRATION *edge) { MIGRATION *ej0, *ej1; RBFNODE *tvert[2]; if (edge == NULL) return; /* triangle on either side? */ get_triangles(tvert, edge); if (tvert[0] == NULL) { /* grow mesh on right */ tvert[0] = find_chull_vert(edge->rbfv[0], edge->rbfv[1]); if (tvert[0] != NULL) { if (tvert[0]->ord > edge->rbfv[0]->ord) ej0 = create_migration(edge->rbfv[0], tvert[0]); else ej0 = create_migration(tvert[0], edge->rbfv[0]); if (tvert[0]->ord > edge->rbfv[1]->ord) ej1 = create_migration(edge->rbfv[1], tvert[0]); else ej1 = create_migration(tvert[0], edge->rbfv[1]); mesh_from_edge(ej0); mesh_from_edge(ej1); } } else if (tvert[1] == NULL) { /* grow mesh on left */ tvert[1] = find_chull_vert(edge->rbfv[1], edge->rbfv[0]); if (tvert[1] != NULL) { if (tvert[1]->ord > edge->rbfv[0]->ord) ej0 = create_migration(edge->rbfv[0], tvert[1]); else ej0 = create_migration(tvert[1], edge->rbfv[0]); if (tvert[1]->ord > edge->rbfv[1]->ord) ej1 = create_migration(edge->rbfv[1], tvert[1]); else ej1 = create_migration(tvert[1], edge->rbfv[1]); mesh_from_edge(ej0); mesh_from_edge(ej1); } } }
/* Create new migration edge and grow mesh recursively around it */
Create new migration edge and grow mesh recursively around it
[ "Create", "new", "migration", "edge", "and", "grow", "mesh", "recursively", "around", "it" ]
static void mesh_from_edge(MIGRATION *edge) { MIGRATION *ej0, *ej1; RBFNODE *tvert[2]; if (edge == NULL) return; get_triangles(tvert, edge); if (tvert[0] == NULL) { tvert[0] = find_chull_vert(edge->rbfv[0], edge->rbfv[1]); if (tvert[0] != NULL) { if (tvert[0]->ord > edge->rbfv[0]->ord) ej0 = create_migration(edge->rbfv[0], tvert[0]); else ej0 = create_migration(tvert[0], edge->rbfv[0]); if (tvert[0]->ord > edge->rbfv[1]->ord) ej1 = create_migration(edge->rbfv[1], tvert[0]); else ej1 = create_migration(tvert[0], edge->rbfv[1]); mesh_from_edge(ej0); mesh_from_edge(ej1); } } else if (tvert[1] == NULL) { tvert[1] = find_chull_vert(edge->rbfv[1], edge->rbfv[0]); if (tvert[1] != NULL) { if (tvert[1]->ord > edge->rbfv[0]->ord) ej0 = create_migration(edge->rbfv[0], tvert[1]); else ej0 = create_migration(tvert[1], edge->rbfv[0]); if (tvert[1]->ord > edge->rbfv[1]->ord) ej1 = create_migration(edge->rbfv[1], tvert[1]); else ej1 = create_migration(tvert[1], edge->rbfv[1]); mesh_from_edge(ej0); mesh_from_edge(ej1); } } }
[ "static", "void", "mesh_from_edge", "(", "MIGRATION", "*", "edge", ")", "{", "MIGRATION", "*", "ej0", ",", "*", "ej1", ";", "RBFNODE", "*", "tvert", "[", "2", "]", ";", "if", "(", "edge", "==", "NULL", ")", "return", ";", "get_triangles", "(", "tvert", ",", "edge", ")", ";", "if", "(", "tvert", "[", "0", "]", "==", "NULL", ")", "{", "tvert", "[", "0", "]", "=", "find_chull_vert", "(", "edge", "->", "rbfv", "[", "0", "]", ",", "edge", "->", "rbfv", "[", "1", "]", ")", ";", "if", "(", "tvert", "[", "0", "]", "!=", "NULL", ")", "{", "if", "(", "tvert", "[", "0", "]", "->", "ord", ">", "edge", "->", "rbfv", "[", "0", "]", "->", "ord", ")", "ej0", "=", "create_migration", "(", "edge", "->", "rbfv", "[", "0", "]", ",", "tvert", "[", "0", "]", ")", ";", "else", "ej0", "=", "create_migration", "(", "tvert", "[", "0", "]", ",", "edge", "->", "rbfv", "[", "0", "]", ")", ";", "if", "(", "tvert", "[", "0", "]", "->", "ord", ">", "edge", "->", "rbfv", "[", "1", "]", "->", "ord", ")", "ej1", "=", "create_migration", "(", "edge", "->", "rbfv", "[", "1", "]", ",", "tvert", "[", "0", "]", ")", ";", "else", "ej1", "=", "create_migration", "(", "tvert", "[", "0", "]", ",", "edge", "->", "rbfv", "[", "1", "]", ")", ";", "mesh_from_edge", "(", "ej0", ")", ";", "mesh_from_edge", "(", "ej1", ")", ";", "}", "}", "else", "if", "(", "tvert", "[", "1", "]", "==", "NULL", ")", "{", "tvert", "[", "1", "]", "=", "find_chull_vert", "(", "edge", "->", "rbfv", "[", "1", "]", ",", "edge", "->", "rbfv", "[", "0", "]", ")", ";", "if", "(", "tvert", "[", "1", "]", "!=", "NULL", ")", "{", "if", "(", "tvert", "[", "1", "]", "->", "ord", ">", "edge", "->", "rbfv", "[", "0", "]", "->", "ord", ")", "ej0", "=", "create_migration", "(", "edge", "->", "rbfv", "[", "0", "]", ",", "tvert", "[", "1", "]", ")", ";", "else", "ej0", "=", "create_migration", "(", "tvert", "[", "1", "]", ",", "edge", "->", "rbfv", "[", "0", "]", ")", ";", "if", "(", "tvert", "[", "1", "]", "->", "ord", ">", "edge", "->", "rbfv", "[", "1", "]", "->", "ord", ")", "ej1", "=", "create_migration", "(", "edge", "->", "rbfv", "[", "1", "]", ",", "tvert", "[", "1", "]", ")", ";", "else", "ej1", "=", "create_migration", "(", "tvert", "[", "1", "]", ",", "edge", "->", "rbfv", "[", "1", "]", ")", ";", "mesh_from_edge", "(", "ej0", ")", ";", "mesh_from_edge", "(", "ej1", ")", ";", "}", "}", "}" ]
Create new migration edge and grow mesh recursively around it
[ "Create", "new", "migration", "edge", "and", "grow", "mesh", "recursively", "around", "it" ]
[ "/* triangle on either side? */", "/* grow mesh on right */", "/* grow mesh on left */" ]
[ { "param": "edge", "type": "MIGRATION" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "edge", "type": "MIGRATION", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
48790131432876e1098cc82304e85001b5b8b666
kalyanam-FMTGA/ray-original
src/cv/bsdfmesh.c
[ "BSD-3-Clause-LBNL" ]
C
comp_bsdf_min
void
static void comp_bsdf_min() { int cnt; int i, target; cnt = 0; for (i = HISTLEN; i--; ) cnt += bsdf_hist[i]; target = cnt/100; /* ignore bottom 1% */ cnt = 0; for (i = 0; cnt <= target; i++) cnt += bsdf_hist[i]; bsdf_min = histval(i-1); memset(bsdf_hist, 0, sizeof(bsdf_hist)); }
/* Compute minimum BSDF from histogram and clear it */
Compute minimum BSDF from histogram and clear it
[ "Compute", "minimum", "BSDF", "from", "histogram", "and", "clear", "it" ]
static void comp_bsdf_min() { int cnt; int i, target; cnt = 0; for (i = HISTLEN; i--; ) cnt += bsdf_hist[i]; target = cnt/100; cnt = 0; for (i = 0; cnt <= target; i++) cnt += bsdf_hist[i]; bsdf_min = histval(i-1); memset(bsdf_hist, 0, sizeof(bsdf_hist)); }
[ "static", "void", "comp_bsdf_min", "(", ")", "{", "int", "cnt", ";", "int", "i", ",", "target", ";", "cnt", "=", "0", ";", "for", "(", "i", "=", "HISTLEN", ";", "i", "--", ";", ")", "cnt", "+=", "bsdf_hist", "[", "i", "]", ";", "target", "=", "cnt", "/", "100", ";", "cnt", "=", "0", ";", "for", "(", "i", "=", "0", ";", "cnt", "<=", "target", ";", "i", "++", ")", "cnt", "+=", "bsdf_hist", "[", "i", "]", ";", "bsdf_min", "=", "histval", "(", "i", "-", "1", ")", ";", "memset", "(", "bsdf_hist", ",", "0", ",", "sizeof", "(", "bsdf_hist", ")", ")", ";", "}" ]
Compute minimum BSDF from histogram and clear it
[ "Compute", "minimum", "BSDF", "from", "histogram", "and", "clear", "it" ]
[ "/* ignore bottom 1% */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
48790131432876e1098cc82304e85001b5b8b666
kalyanam-FMTGA/ray-original
src/cv/bsdfmesh.c
[ "BSD-3-Clause-LBNL" ]
C
build_mesh
void
void build_mesh(void) { double best2 = M_PI*M_PI; RBFNODE *shrt_edj[2]; RBFNODE *rbf0, *rbf1; /* check if isotropic */ if (single_plane_incident) { for (rbf0 = dsf_list; rbf0 != NULL; rbf0 = rbf0->next) if (rbf0->next != NULL) create_migration(rbf0, rbf0->next); await_children(nchild); return; } shrt_edj[0] = shrt_edj[1] = NULL; /* start w/ shortest edge */ for (rbf0 = dsf_list; rbf0 != NULL; rbf0 = rbf0->next) for (rbf1 = rbf0->next; rbf1 != NULL; rbf1 = rbf1->next) { double dist2 = 2. - 2.*DOT(rbf0->invec,rbf1->invec); if (dist2 < best2) { shrt_edj[0] = rbf0; shrt_edj[1] = rbf1; best2 = dist2; } } if (shrt_edj[0] == NULL) { fprintf(stderr, "%s: Cannot find shortest edge\n", progname); exit(1); } /* build mesh from this edge */ if (shrt_edj[0]->ord < shrt_edj[1]->ord) mesh_from_edge(create_migration(shrt_edj[0], shrt_edj[1])); else mesh_from_edge(create_migration(shrt_edj[1], shrt_edj[0])); /* compute minimum BSDF */ comp_bsdf_min(); /* complete migrations */ await_children(nchild); }
/* Build our triangle mesh from recorded RBFs */
Build our triangle mesh from recorded RBFs
[ "Build", "our", "triangle", "mesh", "from", "recorded", "RBFs" ]
void build_mesh(void) { double best2 = M_PI*M_PI; RBFNODE *shrt_edj[2]; RBFNODE *rbf0, *rbf1; if (single_plane_incident) { for (rbf0 = dsf_list; rbf0 != NULL; rbf0 = rbf0->next) if (rbf0->next != NULL) create_migration(rbf0, rbf0->next); await_children(nchild); return; } shrt_edj[0] = shrt_edj[1] = NULL; for (rbf0 = dsf_list; rbf0 != NULL; rbf0 = rbf0->next) for (rbf1 = rbf0->next; rbf1 != NULL; rbf1 = rbf1->next) { double dist2 = 2. - 2.*DOT(rbf0->invec,rbf1->invec); if (dist2 < best2) { shrt_edj[0] = rbf0; shrt_edj[1] = rbf1; best2 = dist2; } } if (shrt_edj[0] == NULL) { fprintf(stderr, "%s: Cannot find shortest edge\n", progname); exit(1); } if (shrt_edj[0]->ord < shrt_edj[1]->ord) mesh_from_edge(create_migration(shrt_edj[0], shrt_edj[1])); else mesh_from_edge(create_migration(shrt_edj[1], shrt_edj[0])); comp_bsdf_min(); await_children(nchild); }
[ "void", "build_mesh", "(", "void", ")", "{", "double", "best2", "=", "M_PI", "*", "M_PI", ";", "RBFNODE", "*", "shrt_edj", "[", "2", "]", ";", "RBFNODE", "*", "rbf0", ",", "*", "rbf1", ";", "if", "(", "single_plane_incident", ")", "{", "for", "(", "rbf0", "=", "dsf_list", ";", "rbf0", "!=", "NULL", ";", "rbf0", "=", "rbf0", "->", "next", ")", "if", "(", "rbf0", "->", "next", "!=", "NULL", ")", "create_migration", "(", "rbf0", ",", "rbf0", "->", "next", ")", ";", "await_children", "(", "nchild", ")", ";", "return", ";", "}", "shrt_edj", "[", "0", "]", "=", "shrt_edj", "[", "1", "]", "=", "NULL", ";", "for", "(", "rbf0", "=", "dsf_list", ";", "rbf0", "!=", "NULL", ";", "rbf0", "=", "rbf0", "->", "next", ")", "for", "(", "rbf1", "=", "rbf0", "->", "next", ";", "rbf1", "!=", "NULL", ";", "rbf1", "=", "rbf1", "->", "next", ")", "{", "double", "dist2", "=", "2.", "-", "2.", "*", "DOT", "(", "rbf0", "->", "invec", ",", "rbf1", "->", "invec", ")", ";", "if", "(", "dist2", "<", "best2", ")", "{", "shrt_edj", "[", "0", "]", "=", "rbf0", ";", "shrt_edj", "[", "1", "]", "=", "rbf1", ";", "best2", "=", "dist2", ";", "}", "}", "if", "(", "shrt_edj", "[", "0", "]", "==", "NULL", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "progname", ")", ";", "exit", "(", "1", ")", ";", "}", "if", "(", "shrt_edj", "[", "0", "]", "->", "ord", "<", "shrt_edj", "[", "1", "]", "->", "ord", ")", "mesh_from_edge", "(", "create_migration", "(", "shrt_edj", "[", "0", "]", ",", "shrt_edj", "[", "1", "]", ")", ")", ";", "else", "mesh_from_edge", "(", "create_migration", "(", "shrt_edj", "[", "1", "]", ",", "shrt_edj", "[", "0", "]", ")", ")", ";", "comp_bsdf_min", "(", ")", ";", "await_children", "(", "nchild", ")", ";", "}" ]
Build our triangle mesh from recorded RBFs
[ "Build", "our", "triangle", "mesh", "from", "recorded", "RBFs" ]
[ "/* check if isotropic */", "/* start w/ shortest edge */", "/* build mesh from this edge */", "/* compute minimum BSDF */", "/* complete migrations */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
e4f4f3696d25e2965b66c01f82092264962d8068
kalyanam-FMTGA/ray-original
src/cv/bsdfrbf.c
[ "BSD-3-Clause-LBNL" ]
C
compute_radii
void
static void compute_radii(void) { unsigned int fill_grid[GRIDRES][GRIDRES]; unsigned short fill_cnt[GRIDRES][GRIDRES]; FVECT ovec0, ovec1; double ang2, lastang2; int r, i, j, jn, ii, jj, inear, jnear; r = GRIDRES/2; /* proceed in zig-zag */ for (i = 0; i < GRIDRES; i++) for (jn = 0; jn < GRIDRES; jn++) { j = (i&1) ? jn : GRIDRES-1-jn; if (dsf_grid[i][j].nval) /* find empty grid pos. */ continue; ovec_from_pos(ovec0, i, j); inear = jnear = -1; /* find nearest non-empty */ lastang2 = M_PI*M_PI; for (ii = i-r; ii <= i+r; ii++) { if (ii < 0) continue; if (ii >= GRIDRES) break; for (jj = j-r; jj <= j+r; jj++) { if (jj < 0) continue; if (jj >= GRIDRES) break; if (!dsf_grid[ii][jj].nval) continue; ovec_from_pos(ovec1, ii, jj); ang2 = 2. - 2.*DOT(ovec0,ovec1); if (ang2 >= lastang2) continue; lastang2 = ang2; inear = ii; jnear = jj; } } if (inear < 0) { fprintf(stderr, "%s: Could not find non-empty neighbor!\n", progname); exit(1); } ang2 = sqrt(lastang2); r = ANG2R(ang2); /* record if > previous */ if (r > dsf_grid[inear][jnear].crad) dsf_grid[inear][jnear].crad = r; /* next search radius */ r = ang2*(2.*GRIDRES/M_PI) + 3; } /* blur radii over hemisphere */ memset(fill_grid, 0, sizeof(fill_grid)); memset(fill_cnt, 0, sizeof(fill_cnt)); for (i = 0; i < GRIDRES; i++) for (j = 0; j < GRIDRES; j++) { if (!dsf_grid[i][j].crad) continue; /* missing distance */ r = R2ANG(dsf_grid[i][j].crad)*(2.*RSCA*GRIDRES/M_PI); for (ii = i-r; ii <= i+r; ii++) { if (ii < 0) continue; if (ii >= GRIDRES) break; for (jj = j-r; jj <= j+r; jj++) { if (jj < 0) continue; if (jj >= GRIDRES) break; if ((ii-i)*(ii-i) + (jj-j)*(jj-j) > r*r) continue; fill_grid[ii][jj] += dsf_grid[i][j].crad; fill_cnt[ii][jj]++; } } } /* copy back blurred radii */ for (i = 0; i < GRIDRES; i++) for (j = 0; j < GRIDRES; j++) if (fill_cnt[i][j]) dsf_grid[i][j].crad = fill_grid[i][j]/fill_cnt[i][j]; }
/* Compute radii for non-empty bins */ /* (distance to furthest empty bin for which non-empty bin is the closest) */
Compute radii for non-empty bins (distance to furthest empty bin for which non-empty bin is the closest)
[ "Compute", "radii", "for", "non", "-", "empty", "bins", "(", "distance", "to", "furthest", "empty", "bin", "for", "which", "non", "-", "empty", "bin", "is", "the", "closest", ")" ]
static void compute_radii(void) { unsigned int fill_grid[GRIDRES][GRIDRES]; unsigned short fill_cnt[GRIDRES][GRIDRES]; FVECT ovec0, ovec1; double ang2, lastang2; int r, i, j, jn, ii, jj, inear, jnear; r = GRIDRES/2; for (i = 0; i < GRIDRES; i++) for (jn = 0; jn < GRIDRES; jn++) { j = (i&1) ? jn : GRIDRES-1-jn; if (dsf_grid[i][j].nval) continue; ovec_from_pos(ovec0, i, j); inear = jnear = -1; lastang2 = M_PI*M_PI; for (ii = i-r; ii <= i+r; ii++) { if (ii < 0) continue; if (ii >= GRIDRES) break; for (jj = j-r; jj <= j+r; jj++) { if (jj < 0) continue; if (jj >= GRIDRES) break; if (!dsf_grid[ii][jj].nval) continue; ovec_from_pos(ovec1, ii, jj); ang2 = 2. - 2.*DOT(ovec0,ovec1); if (ang2 >= lastang2) continue; lastang2 = ang2; inear = ii; jnear = jj; } } if (inear < 0) { fprintf(stderr, "%s: Could not find non-empty neighbor!\n", progname); exit(1); } ang2 = sqrt(lastang2); r = ANG2R(ang2); if (r > dsf_grid[inear][jnear].crad) dsf_grid[inear][jnear].crad = r; r = ang2*(2.*GRIDRES/M_PI) + 3; } memset(fill_grid, 0, sizeof(fill_grid)); memset(fill_cnt, 0, sizeof(fill_cnt)); for (i = 0; i < GRIDRES; i++) for (j = 0; j < GRIDRES; j++) { if (!dsf_grid[i][j].crad) continue; r = R2ANG(dsf_grid[i][j].crad)*(2.*RSCA*GRIDRES/M_PI); for (ii = i-r; ii <= i+r; ii++) { if (ii < 0) continue; if (ii >= GRIDRES) break; for (jj = j-r; jj <= j+r; jj++) { if (jj < 0) continue; if (jj >= GRIDRES) break; if ((ii-i)*(ii-i) + (jj-j)*(jj-j) > r*r) continue; fill_grid[ii][jj] += dsf_grid[i][j].crad; fill_cnt[ii][jj]++; } } } for (i = 0; i < GRIDRES; i++) for (j = 0; j < GRIDRES; j++) if (fill_cnt[i][j]) dsf_grid[i][j].crad = fill_grid[i][j]/fill_cnt[i][j]; }
[ "static", "void", "compute_radii", "(", "void", ")", "{", "unsigned", "int", "fill_grid", "[", "GRIDRES", "]", "[", "GRIDRES", "]", ";", "unsigned", "short", "fill_cnt", "[", "GRIDRES", "]", "[", "GRIDRES", "]", ";", "FVECT", "ovec0", ",", "ovec1", ";", "double", "ang2", ",", "lastang2", ";", "int", "r", ",", "i", ",", "j", ",", "jn", ",", "ii", ",", "jj", ",", "inear", ",", "jnear", ";", "r", "=", "GRIDRES", "/", "2", ";", "for", "(", "i", "=", "0", ";", "i", "<", "GRIDRES", ";", "i", "++", ")", "for", "(", "jn", "=", "0", ";", "jn", "<", "GRIDRES", ";", "jn", "++", ")", "{", "j", "=", "(", "i", "&", "1", ")", "?", "jn", ":", "GRIDRES", "-", "1", "-", "jn", ";", "if", "(", "dsf_grid", "[", "i", "]", "[", "j", "]", ".", "nval", ")", "continue", ";", "ovec_from_pos", "(", "ovec0", ",", "i", ",", "j", ")", ";", "inear", "=", "jnear", "=", "-1", ";", "lastang2", "=", "M_PI", "*", "M_PI", ";", "for", "(", "ii", "=", "i", "-", "r", ";", "ii", "<=", "i", "+", "r", ";", "ii", "++", ")", "{", "if", "(", "ii", "<", "0", ")", "continue", ";", "if", "(", "ii", ">=", "GRIDRES", ")", "break", ";", "for", "(", "jj", "=", "j", "-", "r", ";", "jj", "<=", "j", "+", "r", ";", "jj", "++", ")", "{", "if", "(", "jj", "<", "0", ")", "continue", ";", "if", "(", "jj", ">=", "GRIDRES", ")", "break", ";", "if", "(", "!", "dsf_grid", "[", "ii", "]", "[", "jj", "]", ".", "nval", ")", "continue", ";", "ovec_from_pos", "(", "ovec1", ",", "ii", ",", "jj", ")", ";", "ang2", "=", "2.", "-", "2.", "*", "DOT", "(", "ovec0", ",", "ovec1", ")", ";", "if", "(", "ang2", ">=", "lastang2", ")", "continue", ";", "lastang2", "=", "ang2", ";", "inear", "=", "ii", ";", "jnear", "=", "jj", ";", "}", "}", "if", "(", "inear", "<", "0", ")", "{", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "progname", ")", ";", "exit", "(", "1", ")", ";", "}", "ang2", "=", "sqrt", "(", "lastang2", ")", ";", "r", "=", "ANG2R", "(", "ang2", ")", ";", "if", "(", "r", ">", "dsf_grid", "[", "inear", "]", "[", "jnear", "]", ".", "crad", ")", "dsf_grid", "[", "inear", "]", "[", "jnear", "]", ".", "crad", "=", "r", ";", "r", "=", "ang2", "*", "(", "2.", "*", "GRIDRES", "/", "M_PI", ")", "+", "3", ";", "}", "memset", "(", "fill_grid", ",", "0", ",", "sizeof", "(", "fill_grid", ")", ")", ";", "memset", "(", "fill_cnt", ",", "0", ",", "sizeof", "(", "fill_cnt", ")", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "GRIDRES", ";", "i", "++", ")", "for", "(", "j", "=", "0", ";", "j", "<", "GRIDRES", ";", "j", "++", ")", "{", "if", "(", "!", "dsf_grid", "[", "i", "]", "[", "j", "]", ".", "crad", ")", "continue", ";", "r", "=", "R2ANG", "(", "dsf_grid", "[", "i", "]", "[", "j", "]", ".", "crad", ")", "*", "(", "2.", "*", "RSCA", "*", "GRIDRES", "/", "M_PI", ")", ";", "for", "(", "ii", "=", "i", "-", "r", ";", "ii", "<=", "i", "+", "r", ";", "ii", "++", ")", "{", "if", "(", "ii", "<", "0", ")", "continue", ";", "if", "(", "ii", ">=", "GRIDRES", ")", "break", ";", "for", "(", "jj", "=", "j", "-", "r", ";", "jj", "<=", "j", "+", "r", ";", "jj", "++", ")", "{", "if", "(", "jj", "<", "0", ")", "continue", ";", "if", "(", "jj", ">=", "GRIDRES", ")", "break", ";", "if", "(", "(", "ii", "-", "i", ")", "*", "(", "ii", "-", "i", ")", "+", "(", "jj", "-", "j", ")", "*", "(", "jj", "-", "j", ")", ">", "r", "*", "r", ")", "continue", ";", "fill_grid", "[", "ii", "]", "[", "jj", "]", "+=", "dsf_grid", "[", "i", "]", "[", "j", "]", ".", "crad", ";", "fill_cnt", "[", "ii", "]", "[", "jj", "]", "++", ";", "}", "}", "}", "for", "(", "i", "=", "0", ";", "i", "<", "GRIDRES", ";", "i", "++", ")", "for", "(", "j", "=", "0", ";", "j", "<", "GRIDRES", ";", "j", "++", ")", "if", "(", "fill_cnt", "[", "i", "]", "[", "j", "]", ")", "dsf_grid", "[", "i", "]", "[", "j", "]", ".", "crad", "=", "fill_grid", "[", "i", "]", "[", "j", "]", "/", "fill_cnt", "[", "i", "]", "[", "j", "]", ";", "}" ]
Compute radii for non-empty bins (distance to furthest empty bin for which non-empty bin is the closest)
[ "Compute", "radii", "for", "non", "-", "empty", "bins", "(", "distance", "to", "furthest", "empty", "bin", "for", "which", "non", "-", "empty", "bin", "is", "the", "closest", ")" ]
[ "/* proceed in zig-zag */", "/* find empty grid pos. */", "/* find nearest non-empty */", "/* record if > previous */", "/* next search radius */", "/* blur radii over hemisphere */", "/* missing distance */", "/* copy back blurred radii */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
e4f4f3696d25e2965b66c01f82092264962d8068
kalyanam-FMTGA/ray-original
src/cv/bsdfrbf.c
[ "BSD-3-Clause-LBNL" ]
C
cull_values
void
static void cull_values(void) { FVECT ovec0, ovec1; double maxang, maxang2; int i, j, ii, jj, r; /* simple greedy algorithm */ for (i = 0; i < GRIDRES; i++) for (j = 0; j < GRIDRES; j++) { if (!dsf_grid[i][j].nval) continue; if (!dsf_grid[i][j].crad) continue; /* shouldn't happen */ ovec_from_pos(ovec0, i, j); maxang = 2.*R2ANG(dsf_grid[i][j].crad); if (maxang > ovec0[2]) /* clamp near horizon */ maxang = ovec0[2]; r = maxang*(2.*GRIDRES/M_PI) + 1; maxang2 = maxang*maxang; for (ii = i-r; ii <= i+r; ii++) { if (ii < 0) continue; if (ii >= GRIDRES) break; for (jj = j-r; jj <= j+r; jj++) { if (jj < 0) continue; if (jj >= GRIDRES) break; if (!dsf_grid[ii][jj].nval) continue; if ((ii == i) & (jj == j)) continue; /* don't get self-absorbed */ ovec_from_pos(ovec1, ii, jj); if (2. - 2.*DOT(ovec0,ovec1) >= maxang2) continue; /* absorb sum */ dsf_grid[i][j].vsum += dsf_grid[ii][jj].vsum; dsf_grid[i][j].nval += dsf_grid[ii][jj].nval; /* keep value, though */ dsf_grid[ii][jj].vsum /= (float)dsf_grid[ii][jj].nval; dsf_grid[ii][jj].nval = 0; } } } /* final averaging pass */ for (i = 0; i < GRIDRES; i++) for (j = 0; j < GRIDRES; j++) if (dsf_grid[i][j].nval > 1) { dsf_grid[i][j].vsum /= (float)dsf_grid[i][j].nval; dsf_grid[i][j].nval = 1; } }
/* Cull points for more uniform distribution, leave all nval 0 or 1 */
Cull points for more uniform distribution, leave all nval 0 or 1
[ "Cull", "points", "for", "more", "uniform", "distribution", "leave", "all", "nval", "0", "or", "1" ]
static void cull_values(void) { FVECT ovec0, ovec1; double maxang, maxang2; int i, j, ii, jj, r; for (i = 0; i < GRIDRES; i++) for (j = 0; j < GRIDRES; j++) { if (!dsf_grid[i][j].nval) continue; if (!dsf_grid[i][j].crad) continue; ovec_from_pos(ovec0, i, j); maxang = 2.*R2ANG(dsf_grid[i][j].crad); if (maxang > ovec0[2]) maxang = ovec0[2]; r = maxang*(2.*GRIDRES/M_PI) + 1; maxang2 = maxang*maxang; for (ii = i-r; ii <= i+r; ii++) { if (ii < 0) continue; if (ii >= GRIDRES) break; for (jj = j-r; jj <= j+r; jj++) { if (jj < 0) continue; if (jj >= GRIDRES) break; if (!dsf_grid[ii][jj].nval) continue; if ((ii == i) & (jj == j)) continue; ovec_from_pos(ovec1, ii, jj); if (2. - 2.*DOT(ovec0,ovec1) >= maxang2) continue; dsf_grid[i][j].vsum += dsf_grid[ii][jj].vsum; dsf_grid[i][j].nval += dsf_grid[ii][jj].nval; dsf_grid[ii][jj].vsum /= (float)dsf_grid[ii][jj].nval; dsf_grid[ii][jj].nval = 0; } } } for (i = 0; i < GRIDRES; i++) for (j = 0; j < GRIDRES; j++) if (dsf_grid[i][j].nval > 1) { dsf_grid[i][j].vsum /= (float)dsf_grid[i][j].nval; dsf_grid[i][j].nval = 1; } }
[ "static", "void", "cull_values", "(", "void", ")", "{", "FVECT", "ovec0", ",", "ovec1", ";", "double", "maxang", ",", "maxang2", ";", "int", "i", ",", "j", ",", "ii", ",", "jj", ",", "r", ";", "for", "(", "i", "=", "0", ";", "i", "<", "GRIDRES", ";", "i", "++", ")", "for", "(", "j", "=", "0", ";", "j", "<", "GRIDRES", ";", "j", "++", ")", "{", "if", "(", "!", "dsf_grid", "[", "i", "]", "[", "j", "]", ".", "nval", ")", "continue", ";", "if", "(", "!", "dsf_grid", "[", "i", "]", "[", "j", "]", ".", "crad", ")", "continue", ";", "ovec_from_pos", "(", "ovec0", ",", "i", ",", "j", ")", ";", "maxang", "=", "2.", "*", "R2ANG", "(", "dsf_grid", "[", "i", "]", "[", "j", "]", ".", "crad", ")", ";", "if", "(", "maxang", ">", "ovec0", "[", "2", "]", ")", "maxang", "=", "ovec0", "[", "2", "]", ";", "r", "=", "maxang", "*", "(", "2.", "*", "GRIDRES", "/", "M_PI", ")", "+", "1", ";", "maxang2", "=", "maxang", "*", "maxang", ";", "for", "(", "ii", "=", "i", "-", "r", ";", "ii", "<=", "i", "+", "r", ";", "ii", "++", ")", "{", "if", "(", "ii", "<", "0", ")", "continue", ";", "if", "(", "ii", ">=", "GRIDRES", ")", "break", ";", "for", "(", "jj", "=", "j", "-", "r", ";", "jj", "<=", "j", "+", "r", ";", "jj", "++", ")", "{", "if", "(", "jj", "<", "0", ")", "continue", ";", "if", "(", "jj", ">=", "GRIDRES", ")", "break", ";", "if", "(", "!", "dsf_grid", "[", "ii", "]", "[", "jj", "]", ".", "nval", ")", "continue", ";", "if", "(", "(", "ii", "==", "i", ")", "&", "(", "jj", "==", "j", ")", ")", "continue", ";", "ovec_from_pos", "(", "ovec1", ",", "ii", ",", "jj", ")", ";", "if", "(", "2.", "-", "2.", "*", "DOT", "(", "ovec0", ",", "ovec1", ")", ">=", "maxang2", ")", "continue", ";", "dsf_grid", "[", "i", "]", "[", "j", "]", ".", "vsum", "+=", "dsf_grid", "[", "ii", "]", "[", "jj", "]", ".", "vsum", ";", "dsf_grid", "[", "i", "]", "[", "j", "]", ".", "nval", "+=", "dsf_grid", "[", "ii", "]", "[", "jj", "]", ".", "nval", ";", "dsf_grid", "[", "ii", "]", "[", "jj", "]", ".", "vsum", "/=", "(", "float", ")", "dsf_grid", "[", "ii", "]", "[", "jj", "]", ".", "nval", ";", "dsf_grid", "[", "ii", "]", "[", "jj", "]", ".", "nval", "=", "0", ";", "}", "}", "}", "for", "(", "i", "=", "0", ";", "i", "<", "GRIDRES", ";", "i", "++", ")", "for", "(", "j", "=", "0", ";", "j", "<", "GRIDRES", ";", "j", "++", ")", "if", "(", "dsf_grid", "[", "i", "]", "[", "j", "]", ".", "nval", ">", "1", ")", "{", "dsf_grid", "[", "i", "]", "[", "j", "]", ".", "vsum", "/=", "(", "float", ")", "dsf_grid", "[", "i", "]", "[", "j", "]", ".", "nval", ";", "dsf_grid", "[", "i", "]", "[", "j", "]", ".", "nval", "=", "1", ";", "}", "}" ]
Cull points for more uniform distribution, leave all nval 0 or 1
[ "Cull", "points", "for", "more", "uniform", "distribution", "leave", "all", "nval", "0", "or", "1" ]
[ "/* simple greedy algorithm */", "/* shouldn't happen */", "/* clamp near horizon */", "/* don't get self-absorbed */", "/* absorb sum */", "/* keep value, though */", "/* final averaging pass */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
e4f4f3696d25e2965b66c01f82092264962d8068
kalyanam-FMTGA/ray-original
src/cv/bsdfrbf.c
[ "BSD-3-Clause-LBNL" ]
C
make_rbfrep
RBFNODE
RBFNODE * make_rbfrep(void) { int niter = 16; double lastVar, thisVar = 100.; int nn; RBFNODE *newnode; RBFVAL *itera; int i, j; /* compute RBF radii */ compute_radii(); /* coagulate lobes */ cull_values(); nn = 0; /* count selected bins */ for (i = 0; i < GRIDRES; i++) for (j = 0; j < GRIDRES; j++) nn += dsf_grid[i][j].nval; /* allocate RBF array */ newnode = (RBFNODE *)malloc(sizeof(RBFNODE) + sizeof(RBFVAL)*(nn-1)); if (newnode == NULL) goto memerr; newnode->ord = -1; newnode->next = NULL; newnode->ejl = NULL; newnode->invec[2] = sin((M_PI/180.)*theta_in_deg); newnode->invec[0] = cos((M_PI/180.)*phi_in_deg)*newnode->invec[2]; newnode->invec[1] = sin((M_PI/180.)*phi_in_deg)*newnode->invec[2]; newnode->invec[2] = input_orient*sqrt(1. - newnode->invec[2]*newnode->invec[2]); newnode->vtotal = 0; newnode->nrbf = nn; nn = 0; /* fill RBF array */ for (i = 0; i < GRIDRES; i++) for (j = 0; j < GRIDRES; j++) if (dsf_grid[i][j].nval) { newnode->rbfa[nn].peak = dsf_grid[i][j].vsum; newnode->rbfa[nn].crad = RSCA*dsf_grid[i][j].crad + .5; newnode->rbfa[nn].gx = i; newnode->rbfa[nn].gy = j; ++nn; } /* iterate to improve interpolation accuracy */ itera = (RBFVAL *)malloc(sizeof(RBFVAL)*newnode->nrbf); if (itera == NULL) goto memerr; memcpy(itera, newnode->rbfa, sizeof(RBFVAL)*newnode->nrbf); do { double dsum = 0, dsum2 = 0; nn = 0; for (i = 0; i < GRIDRES; i++) for (j = 0; j < GRIDRES; j++) if (dsf_grid[i][j].nval) { FVECT odir; double corr; ovec_from_pos(odir, i, j); itera[nn++].peak *= corr = dsf_grid[i][j].vsum / eval_rbfrep(newnode, odir); dsum += 1. - corr; dsum2 += (1.-corr)*(1.-corr); } memcpy(newnode->rbfa, itera, sizeof(RBFVAL)*newnode->nrbf); lastVar = thisVar; thisVar = dsum2/(double)nn; #ifdef DEBUG fprintf(stderr, "Avg., RMS error: %.1f%% %.1f%%\n", 100.*dsum/(double)nn, 100.*sqrt(thisVar)); #endif } while (--niter > 0 && lastVar-thisVar > 0.02*lastVar); free(itera); nn = 0; /* compute sum for normalization */ while (nn < newnode->nrbf) newnode->vtotal += rbf_volume(&newnode->rbfa[nn++]); #ifdef DEBUG fprintf(stderr, "Integrated DSF at (%.1f,%.1f) deg. is %.2f\n", get_theta180(newnode->invec), get_phi360(newnode->invec), newnode->vtotal); #endif insert_dsf(newnode); return(newnode); memerr: fprintf(stderr, "%s: Out of memory in make_rbfrep()\n", progname); exit(1); }
/* Count up filled nodes and build RBF representation from current grid */
Count up filled nodes and build RBF representation from current grid
[ "Count", "up", "filled", "nodes", "and", "build", "RBF", "representation", "from", "current", "grid" ]
RBFNODE * make_rbfrep(void) { int niter = 16; double lastVar, thisVar = 100.; int nn; RBFNODE *newnode; RBFVAL *itera; int i, j; compute_radii(); cull_values(); nn = 0; for (i = 0; i < GRIDRES; i++) for (j = 0; j < GRIDRES; j++) nn += dsf_grid[i][j].nval; newnode = (RBFNODE *)malloc(sizeof(RBFNODE) + sizeof(RBFVAL)*(nn-1)); if (newnode == NULL) goto memerr; newnode->ord = -1; newnode->next = NULL; newnode->ejl = NULL; newnode->invec[2] = sin((M_PI/180.)*theta_in_deg); newnode->invec[0] = cos((M_PI/180.)*phi_in_deg)*newnode->invec[2]; newnode->invec[1] = sin((M_PI/180.)*phi_in_deg)*newnode->invec[2]; newnode->invec[2] = input_orient*sqrt(1. - newnode->invec[2]*newnode->invec[2]); newnode->vtotal = 0; newnode->nrbf = nn; nn = 0; for (i = 0; i < GRIDRES; i++) for (j = 0; j < GRIDRES; j++) if (dsf_grid[i][j].nval) { newnode->rbfa[nn].peak = dsf_grid[i][j].vsum; newnode->rbfa[nn].crad = RSCA*dsf_grid[i][j].crad + .5; newnode->rbfa[nn].gx = i; newnode->rbfa[nn].gy = j; ++nn; } itera = (RBFVAL *)malloc(sizeof(RBFVAL)*newnode->nrbf); if (itera == NULL) goto memerr; memcpy(itera, newnode->rbfa, sizeof(RBFVAL)*newnode->nrbf); do { double dsum = 0, dsum2 = 0; nn = 0; for (i = 0; i < GRIDRES; i++) for (j = 0; j < GRIDRES; j++) if (dsf_grid[i][j].nval) { FVECT odir; double corr; ovec_from_pos(odir, i, j); itera[nn++].peak *= corr = dsf_grid[i][j].vsum / eval_rbfrep(newnode, odir); dsum += 1. - corr; dsum2 += (1.-corr)*(1.-corr); } memcpy(newnode->rbfa, itera, sizeof(RBFVAL)*newnode->nrbf); lastVar = thisVar; thisVar = dsum2/(double)nn; #ifdef DEBUG fprintf(stderr, "Avg., RMS error: %.1f%% %.1f%%\n", 100.*dsum/(double)nn, 100.*sqrt(thisVar)); #endif } while (--niter > 0 && lastVar-thisVar > 0.02*lastVar); free(itera); nn = 0; while (nn < newnode->nrbf) newnode->vtotal += rbf_volume(&newnode->rbfa[nn++]); #ifdef DEBUG fprintf(stderr, "Integrated DSF at (%.1f,%.1f) deg. is %.2f\n", get_theta180(newnode->invec), get_phi360(newnode->invec), newnode->vtotal); #endif insert_dsf(newnode); return(newnode); memerr: fprintf(stderr, "%s: Out of memory in make_rbfrep()\n", progname); exit(1); }
[ "RBFNODE", "*", "make_rbfrep", "(", "void", ")", "{", "int", "niter", "=", "16", ";", "double", "lastVar", ",", "thisVar", "=", "100.", ";", "int", "nn", ";", "RBFNODE", "*", "newnode", ";", "RBFVAL", "*", "itera", ";", "int", "i", ",", "j", ";", "compute_radii", "(", ")", ";", "cull_values", "(", ")", ";", "nn", "=", "0", ";", "for", "(", "i", "=", "0", ";", "i", "<", "GRIDRES", ";", "i", "++", ")", "for", "(", "j", "=", "0", ";", "j", "<", "GRIDRES", ";", "j", "++", ")", "nn", "+=", "dsf_grid", "[", "i", "]", "[", "j", "]", ".", "nval", ";", "newnode", "=", "(", "RBFNODE", "*", ")", "malloc", "(", "sizeof", "(", "RBFNODE", ")", "+", "sizeof", "(", "RBFVAL", ")", "*", "(", "nn", "-", "1", ")", ")", ";", "if", "(", "newnode", "==", "NULL", ")", "goto", "memerr", ";", "newnode", "->", "ord", "=", "-1", ";", "newnode", "->", "next", "=", "NULL", ";", "newnode", "->", "ejl", "=", "NULL", ";", "newnode", "->", "invec", "[", "2", "]", "=", "sin", "(", "(", "M_PI", "/", "180.", ")", "*", "theta_in_deg", ")", ";", "newnode", "->", "invec", "[", "0", "]", "=", "cos", "(", "(", "M_PI", "/", "180.", ")", "*", "phi_in_deg", ")", "*", "newnode", "->", "invec", "[", "2", "]", ";", "newnode", "->", "invec", "[", "1", "]", "=", "sin", "(", "(", "M_PI", "/", "180.", ")", "*", "phi_in_deg", ")", "*", "newnode", "->", "invec", "[", "2", "]", ";", "newnode", "->", "invec", "[", "2", "]", "=", "input_orient", "*", "sqrt", "(", "1.", "-", "newnode", "->", "invec", "[", "2", "]", "*", "newnode", "->", "invec", "[", "2", "]", ")", ";", "newnode", "->", "vtotal", "=", "0", ";", "newnode", "->", "nrbf", "=", "nn", ";", "nn", "=", "0", ";", "for", "(", "i", "=", "0", ";", "i", "<", "GRIDRES", ";", "i", "++", ")", "for", "(", "j", "=", "0", ";", "j", "<", "GRIDRES", ";", "j", "++", ")", "if", "(", "dsf_grid", "[", "i", "]", "[", "j", "]", ".", "nval", ")", "{", "newnode", "->", "rbfa", "[", "nn", "]", ".", "peak", "=", "dsf_grid", "[", "i", "]", "[", "j", "]", ".", "vsum", ";", "newnode", "->", "rbfa", "[", "nn", "]", ".", "crad", "=", "RSCA", "*", "dsf_grid", "[", "i", "]", "[", "j", "]", ".", "crad", "+", ".5", ";", "newnode", "->", "rbfa", "[", "nn", "]", ".", "gx", "=", "i", ";", "newnode", "->", "rbfa", "[", "nn", "]", ".", "gy", "=", "j", ";", "++", "nn", ";", "}", "itera", "=", "(", "RBFVAL", "*", ")", "malloc", "(", "sizeof", "(", "RBFVAL", ")", "*", "newnode", "->", "nrbf", ")", ";", "if", "(", "itera", "==", "NULL", ")", "goto", "memerr", ";", "memcpy", "(", "itera", ",", "newnode", "->", "rbfa", ",", "sizeof", "(", "RBFVAL", ")", "*", "newnode", "->", "nrbf", ")", ";", "do", "{", "double", "dsum", "=", "0", ",", "dsum2", "=", "0", ";", "nn", "=", "0", ";", "for", "(", "i", "=", "0", ";", "i", "<", "GRIDRES", ";", "i", "++", ")", "for", "(", "j", "=", "0", ";", "j", "<", "GRIDRES", ";", "j", "++", ")", "if", "(", "dsf_grid", "[", "i", "]", "[", "j", "]", ".", "nval", ")", "{", "FVECT", "odir", ";", "double", "corr", ";", "ovec_from_pos", "(", "odir", ",", "i", ",", "j", ")", ";", "itera", "[", "nn", "++", "]", ".", "peak", "*=", "corr", "=", "dsf_grid", "[", "i", "]", "[", "j", "]", ".", "vsum", "/", "eval_rbfrep", "(", "newnode", ",", "odir", ")", ";", "dsum", "+=", "1.", "-", "corr", ";", "dsum2", "+=", "(", "1.", "-", "corr", ")", "*", "(", "1.", "-", "corr", ")", ";", "}", "memcpy", "(", "newnode", "->", "rbfa", ",", "itera", ",", "sizeof", "(", "RBFVAL", ")", "*", "newnode", "->", "nrbf", ")", ";", "lastVar", "=", "thisVar", ";", "thisVar", "=", "dsum2", "/", "(", "double", ")", "nn", ";", "#ifdef", "DEBUG", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "100.", "*", "dsum", "/", "(", "double", ")", "nn", ",", "100.", "*", "sqrt", "(", "thisVar", ")", ")", ";", "#endif", "}", "while", "(", "--", "niter", ">", "0", "&&", "lastVar", "-", "thisVar", ">", "0.02", "*", "lastVar", ")", ";", "free", "(", "itera", ")", ";", "nn", "=", "0", ";", "while", "(", "nn", "<", "newnode", "->", "nrbf", ")", "newnode", "->", "vtotal", "+=", "rbf_volume", "(", "&", "newnode", "->", "rbfa", "[", "nn", "++", "]", ")", ";", "#ifdef", "DEBUG", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "get_theta180", "(", "newnode", "->", "invec", ")", ",", "get_phi360", "(", "newnode", "->", "invec", ")", ",", "newnode", "->", "vtotal", ")", ";", "#endif", "insert_dsf", "(", "newnode", ")", ";", "return", "(", "newnode", ")", ";", "memerr", ":", "fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "progname", ")", ";", "exit", "(", "1", ")", ";", "}" ]
Count up filled nodes and build RBF representation from current grid
[ "Count", "up", "filled", "nodes", "and", "build", "RBF", "representation", "from", "current", "grid" ]
[ "/* compute RBF radii */", "/* coagulate lobes */", "/* count selected bins */", "/* allocate RBF array */", "/* fill RBF array */", "/* iterate to improve interpolation accuracy */", "/* compute sum for normalization */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
462d14f56db6c7bb78b6b455d441b7faa8945671
kalyanam-FMTGA/ray-original
src/meta/sort.c
[ "BSD-3-Clause-LBNL" ]
C
sort
void
void sort( /* sort primitives according to pcmp */ FILE *infp, int (*pcmp)() /* compares pointers to pointers to primitives! */ ) { PRIMITIVE *prims[PBSIZE]; /* pointers to primitives */ PLIST primlist; /* our primitives list */ int nprims; short done; do { for (nprims = 0; nprims < PBSIZE; nprims++) { /* read to global */ if ((prims[nprims] = palloc()) == NULL) error(SYSTEM, "memory exhausted in sort"); readp(prims[nprims], infp); if (isglob(prims[nprims]->com)) break; } qsort(prims, nprims, sizeof(*prims), pcmp); /* sort pointer array */ if (nprims < PBSIZE) /* tack on global if one */ nprims++; order(prims, nprims, &primlist); /* make array into list */ sendsort(&primlist, pcmp); /* send to merge sorter */ done = primlist.pbot->com == PEOF; plfree(&primlist); /* free up array */ } while (!done); }
/* * This sort routine does a combination quicksort and * n-ary mergesort */
This sort routine does a combination quicksort and n-ary mergesort
[ "This", "sort", "routine", "does", "a", "combination", "quicksort", "and", "n", "-", "ary", "mergesort" ]
void sort( FILE *infp, int (*pcmp)() ) { PRIMITIVE *prims[PBSIZE]; PLIST primlist; int nprims; short done; do { for (nprims = 0; nprims < PBSIZE; nprims++) { if ((prims[nprims] = palloc()) == NULL) error(SYSTEM, "memory exhausted in sort"); readp(prims[nprims], infp); if (isglob(prims[nprims]->com)) break; } qsort(prims, nprims, sizeof(*prims), pcmp); if (nprims < PBSIZE) nprims++; order(prims, nprims, &primlist); sendsort(&primlist, pcmp); done = primlist.pbot->com == PEOF; plfree(&primlist); } while (!done); }
[ "void", "sort", "(", "FILE", "*", "infp", ",", "int", "(", "*", "pcmp", ")", "(", ")", ")", "{", "PRIMITIVE", "*", "prims", "[", "PBSIZE", "]", ";", "PLIST", "primlist", ";", "int", "nprims", ";", "short", "done", ";", "do", "{", "for", "(", "nprims", "=", "0", ";", "nprims", "<", "PBSIZE", ";", "nprims", "++", ")", "{", "if", "(", "(", "prims", "[", "nprims", "]", "=", "palloc", "(", ")", ")", "==", "NULL", ")", "error", "(", "SYSTEM", ",", "\"", "\"", ")", ";", "readp", "(", "prims", "[", "nprims", "]", ",", "infp", ")", ";", "if", "(", "isglob", "(", "prims", "[", "nprims", "]", "->", "com", ")", ")", "break", ";", "}", "qsort", "(", "prims", ",", "nprims", ",", "sizeof", "(", "*", "prims", ")", ",", "pcmp", ")", ";", "if", "(", "nprims", "<", "PBSIZE", ")", "nprims", "++", ";", "order", "(", "prims", ",", "nprims", ",", "&", "primlist", ")", ";", "sendsort", "(", "&", "primlist", ",", "pcmp", ")", ";", "done", "=", "primlist", ".", "pbot", "->", "com", "==", "PEOF", ";", "plfree", "(", "&", "primlist", ")", ";", "}", "while", "(", "!", "done", ")", ";", "}" ]
This sort routine does a combination quicksort and n-ary mergesort
[ "This", "sort", "routine", "does", "a", "combination", "quicksort", "and", "n", "-", "ary", "mergesort" ]
[ "/* sort primitives according to pcmp */", "/* compares pointers to pointers to primitives! */", "/* pointers to primitives */", "/* our primitives list */", "/* read to global */", "/* sort pointer array */", "/* tack on global if one */", "/* make array into list */", "/* send to merge sorter */", "/* free up array */" ]
[ { "param": "infp", "type": "FILE" }, { "param": "pcmp", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "infp", "type": "FILE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pcmp", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }